Advertisement
2607

s21_string.h

Dec 4th, 2021
1,840
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 10.65 KB | None | 0 0
  1. #ifndef SRC_S21_STRING_H_
  2. #define SRC_S21_STRING_H_
  3. #ifndef s21_NULL
  4. #define s21_NULL ((void *)0)
  5. #endif  // s21_NULL
  6.  
  7. #include <stdio.h>
  8. #include <stdarg.h>
  9. typedef unsigned long s21_size_t;
  10.  
  11. typedef struct parcer_params {
  12.     char flag[6];
  13.     int width;
  14.     int accur;
  15.     char lenght;
  16.     char specif;
  17.     int width_arg_flag;
  18.     int accur_arg_flag;
  19.     int size_format;
  20.     int spec_pos;
  21. } parcer_t;
  22.  
  23. typedef struct int_types {
  24.     long *ld;
  25.     int *d;
  26.     short *h;
  27.     unsigned long *lu;
  28.     unsigned *u;
  29.     unsigned short *hu;
  30. } int_type;
  31.  
  32. typedef struct double_types {
  33.     float *f;
  34.     double *doub;
  35.     long double *l_doub;
  36. } double_type;
  37.  
  38. void *s21_memchr(const void *str, int c, s21_size_t n);
  39. int s21_memcmp(const void *str1, const void *str2, s21_size_t n);
  40. void *s21_memcpy(void *dest, const void *src, s21_size_t n);
  41. void *s21_memmove(void *dest, const void *src, s21_size_t n);
  42. void *s21_memset(void *str, int c, s21_size_t n);
  43. char *s21_strcat(char *dest, const char *src);
  44. char *s21_strncat(char *dest, const char *src, s21_size_t n);
  45. char* s21_strchr(const char *str, int c);
  46. int s21_strcmp(const char *str1, const char *str2);
  47. int s21_strncmp(const char *str1, const char *str2, s21_size_t n);
  48. char *s21_strcpy(char *dest, const char *src);
  49. char *s21_strncpy(char *dest, const char *src, s21_size_t n);
  50. s21_size_t s21_strcspn(const char *str1, const char *str2);
  51. s21_size_t s21_strlen(const char *str);
  52. char *s21_strpbrk(const char *str1, const char *str2);
  53. char *s21_strrchr(const char *str, int c);
  54. s21_size_t s21_strspn(const char *str1, const char *str2);
  55. char *s21_strstr(const char *haystack, const char *needle);
  56. char *s21_strtok(char *str, const char *delim);
  57. void *s21_to_upper(const char *str);
  58. void *s21_to_lower(const char *str);
  59. void *s21_insert(const char *src, const char *str, s21_size_t start_index);
  60. int s21_sscanf(const char *str, const char *format, ...);
  61. int s21_sprintf(char *str, const char *format, ...);
  62. void check_ch(parcer_t *spec, char *str, int ch);
  63. int int_to_str(char *str, long int d);
  64. int str_to_int(char *str, int size);
  65. void test_output(int counter, int counter_buff, const char *format, char *str);
  66. int check(int counter, const char *str, const char *refer, int ref_point_p);
  67. int parcer(const char *format, parcer_t *spec);
  68. void search_spec(int *counter_buff,
  69.                  int *counter,
  70.                  const char *format,
  71.                  char *refer,
  72.                  char *str,
  73.                  int ref_point_p);
  74. int float_e_to_str(parcer_t *spec, long double e, char *str, char specif);
  75. void g_to_str(parcer_t *spec, char *str, va_list temp);
  76. void d_to_str(char *out1, parcer_t *spec, long int d);
  77. long int stepen(long int b);
  78. int dig_counter(long int d);
  79. void get_zero(char *out, int *ii, int stop);
  80. void int_to_oct_hex_str(parcer_t *spec, long long int d, char *str, int n);
  81. void pnt_to_str(parcer_t *spec, long long int int_p, char *str);
  82. void str_to_res_str(parcer_t *spec, char *arg_str, char *str);
  83. void clean_str(char *str, int size_str);
  84. void sscanf_str_to_res(parcer_t *spec, char *src, va_list list_args);
  85. void hex_oct_str_to_int(parcer_t *spec, char *buff, va_list list_args);
  86. void hex_oct_dec_convert(char* buff, int size, parcer_t *spec, va_list list_args, int s_s);
  87. void str_to_float(char *buff, int size, long double *f_arg);
  88. void str_to_ch(char *buff, parcer_t *spec, va_list list_arg);
  89. int check_sign(char **str, int* size);
  90. void double_arg_to_str(char* buff, int size, parcer_t *spec, va_list list_args);
  91.  
  92. char *s21_strerror(int errnum);
  93. static char *ErrorNames1[] = {
  94.     "Undefined error: 0",
  95.     "Operation not permitted",
  96.     "No such file or directory",
  97.     "No such process",
  98.     "Interrupted system call",
  99.     "Input/output error",
  100.     "Device not configured",
  101.     "Argument list too long",
  102.     "Exec format error",
  103.     "Bad file descriptor",
  104.     "No child processes",
  105.     "Resource deadlock avoided",
  106.     "Cannot allocate memory",
  107.     "Permission denied",
  108.     "Bad address",
  109.     "Block device required",
  110.     "Resource busy",
  111.     "File exists",
  112.     "Cross-device link",
  113.     "Operation not supported by device",
  114.     "Not a directory",
  115.     "Is a directory",
  116.     "Invalid argument",
  117.     "Too many open files in system",
  118.     "Too many open files",
  119.     "Inappropriate ioctl for device",
  120.     "Text file busy",
  121.     "File too large",
  122.     "No space left on device",
  123.     "Illegal seek",
  124.     "Read-only file system",
  125.     "Too many links",
  126.     "Broken pipe",
  127.     "Numerical argument out of domain",
  128.     "Result too large",
  129.     "Resource temporarily unavailable",
  130.     "Operation now in progress",
  131.     "Operation already in progress",
  132.     "Socket operation on non-socket",
  133.     "Destination address required",
  134.     "Message too long",
  135.     "Protocol wrong type for socket",
  136.     "Protocol not available",
  137.     "Protocol not supported",
  138.     "Socket type not supported",
  139.     "Operation not supported",
  140.     "Protocol family not supported",
  141.     "Address family not supported by protocol family",
  142.     "Address already in use",
  143.     "Can't assign requested address",
  144.     "Network is down",
  145.     "Network is unreachable",
  146.     "Network dropped connection on reset",
  147.     "Software caused connection abort",
  148.     "Connection reset by peer",
  149.     "No buffer space available",
  150.     "Socket is already connected",
  151.     "Socket is not connected",
  152.     "Can't send after socket shutdown",
  153.     "Too many references: can't splice",
  154.     "Operation timed out",
  155.     "Connection refused",
  156.     "Too many levels of symbolic links",
  157.     "File name too long",
  158.     "Host is down",
  159.     "No route to host",
  160.     "Directory not empty",
  161.     "Too many processes",
  162.     "Too many users",
  163.     "Disc quota exceeded",
  164.     "Stale NFS file handle",
  165.     "Too many levels of remote in path",
  166.     "RPC struct is bad",
  167.     "RPC version wrong",
  168.     "RPC prog. not avail",
  169.     "Program version wrong",
  170.     "Bad procedure for program",
  171.     "No locks available",
  172.     "Function not implemented",
  173.     "Inappropriate file type or format",
  174.     "Authentication error",
  175.     "Need authenticator",
  176.     "Device power is off",
  177.     "Device error",
  178.     "Value too large to be stored in data type",
  179.     "Bad executable (or shared library)",
  180.     "Bad CPU type in executable",
  181.     "Shared library version mismatch",
  182.     "Malformed Mach-o file",
  183.     "Operation canceled",
  184.     "Identifier removed",
  185.     "No message of desired type",
  186.     "Illegal byte sequence",
  187.     "Attribute not found",
  188.     "Bad message",
  189.     "EMULTIHOP (Reserved)",
  190.     "No message available on STREAM",
  191.     "ENOLINK (Reserved)",
  192.     "No STREAM resources",
  193.     "Not a STREAM",
  194.     "Protocol error",
  195.     "STREAM ioctl timeout",
  196.     "Operation not supported on socket",
  197.     "Policy not found",
  198.     "State not recoverable",
  199.     "Previous owner died",
  200.     "Interface output queue is full",
  201.     "Unknown error: 107"
  202. };
  203.  
  204. char *s21_strerror(int errnum);
  205. static char *ErrorNames[] = {
  206.     "No error information",
  207.     "Operation not permitted",
  208.     "No such file or directory",
  209.     "No such process",
  210.     "Interrupted system call",
  211.     "I/O error",
  212.     "No such device or address",
  213.     "Argument list too long",
  214.     "Exec format error",
  215.     "Bad file descriptor",
  216.     "No child process",
  217.     "Resource temporarily unavailable",
  218.     "Out of memory",
  219.     "Permission denied",
  220.     "Bad address",
  221.     "Block device required",
  222.     "Resource busy",
  223.     "File exists",
  224.     "Cross-device link",
  225.     "No such device",
  226.     "Not a directory",
  227.     "Is a directory",
  228.     "Invalid argument",
  229.     "Too many open files in system",
  230.     "No file descriptors available",
  231.     "Not a tty",
  232.     "Text file busy",
  233.     "File too large",
  234.     "No space left on device",
  235.     "Invalid seek",
  236.     "Read-only file system",
  237.     "Too many links",
  238.     "Broken pipe",
  239.     "Domain error",
  240.     "Result not representable",
  241.     "Resource deadlock would occur",
  242.     "Filename too long",
  243.     "No locks available",
  244.     "Function not implemented",
  245.     "Directory not empty",
  246.     "Symbolic link loop",
  247.     "No error information",
  248.     "No message of desired type",
  249.     "Identifier removed",
  250.     "No error information",
  251.     "No error information",
  252.     "No error information",
  253.     "No error information",
  254.     "No error information",
  255.     "No error information",
  256.     "No error information",
  257.     "No error information",
  258.     "No error information",
  259.     "No error information",
  260.     "No error information",
  261.     "No error information",
  262.     "No error information",
  263.     "No error information",
  264.     "No error information",
  265.     "No error information",
  266.     "Device not a stream",
  267.     "No data available",
  268.     "Device timeout",
  269.     "Out of streams resources",
  270.     "No error information",
  271.     "No error information",
  272.     "No error information",
  273.     "Link has been severed",
  274.     "No error information",
  275.     "No error information",
  276.     "No error information",
  277.     "Protocol error",
  278.     "Multihop attempted",
  279.     "No error information",
  280.     "Bad message",
  281.     "Value too large for data type",
  282.     "No error information",
  283.     "File descriptor in bad state",
  284.     "No error information",
  285.     "No error information",
  286.     "No error information",
  287.     "No error information",
  288.     "No error information",
  289.     "No error information",
  290.     "Illegal byte sequence",
  291.     "No error information",
  292.     "No error information",
  293.     "No error information",
  294.     "Not a socket",
  295.     "Destination address required",
  296.     "Message too large",
  297.     "Protocol wrong type for socket",
  298.     "Protocol not available",
  299.     "Protocol not supported",
  300.     "Socket type not supported",
  301.     "Not supported",
  302.     "Protocol family not supported",
  303.     "Address family not supported by protocol",
  304.     "Address in use",
  305.     "Address not available",
  306.     "Network is down",
  307.     "Network unreachable",
  308.     "Connection reset by network",
  309.     "Connection aborted",
  310.     "Connection reset by peer",
  311.     "No buffer space available",
  312.     "Socket is connected",
  313.     "Socket not connected",
  314.     "Cannot send after socket shutdown",
  315.     "No error information",
  316.     "Operation timed out",
  317.     "Connection refused",
  318.     "Host is down",
  319.     "Host is unreachable",
  320.     "Operation already in progress",
  321.     "Operation in progress",
  322.     "Stale file handle",
  323.     "No error information",
  324.     "No error information",
  325.     "No error information",
  326.     "No error information",
  327.     "Remote I/O error",
  328.     "Quota exceeded",
  329.     "No medium found",
  330.     "Wrong medium type",
  331.     "Operation canceled",
  332.     "No error information",
  333.     "No error information",
  334.     "No error information",
  335.     "No error information",
  336.     "Previous owner died",
  337.     "State not recoverable",
  338.     "No error information",
  339.     };
  340.  
  341. #endif  // SRC_S21_STRING_H_
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement