Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char *s21_strerror(int errnum) {
- char *error_message = NULL;
- if (errnum > -1 && errnum < 107) { // Если ошибка существует
- error_message = (char*)sys_errlist[errnum];
- } else if (errnum > 106) {
- char unknown_error[30] = "Unknown error: ";
- char number[20]; // Для первода errnum в строку
- int count = 0;
- while (errnum / 10 != 0) {
- number[count++] = (errnum % 10) + '0';
- errnum /= 10;
- }
- number[count++] = errnum + '0';
- number[count] = '\0';
- char buf;
- for (int i = 0; i < count / 2; i++) {
- buf = number[i];
- number[i] = number[count - 1 - i];
- number[count- 1 - i] = buf;
- }
- s21_strcat(unknown_error, number);
- static char* result[1];
- result[0] = (char*)malloc(s21_strlen(unknown_error)*sizeof(char));
- for (s21_size_t i = 0; i < s21_strlen(unknown_error); i++){
- result[0][i] = unknown_error[i];
- }
- error_message = result[0];
- free(result[0]); // Никаких утечек памяти в мою смену
- } else {
- errnum *= -1;
- char unknown_error[30] = "Unknown error: -";
- char number[20]; // Для первода errnum в строку
- int count = 0;
- while (errnum / 10 != 0) {
- number[count++] = (errnum % 10) + '0';
- errnum /= 10;
- }
- number[count++] = errnum + '0';
- number[count] = '\0';
- char buf;
- for (int i = 0; i < count / 2; i++) {
- buf = number[i];
- number[i] = number[count - 1 - i];
- number[count- 1 - i] = buf;
- }
- s21_strcat(unknown_error, number);
- static char* result[1];
- result[0] = (char*)malloc(s21_strlen(unknown_error)*sizeof(char));
- for (s21_size_t i = 0; i < s21_strlen(unknown_error); i++){
- result[0][i] = unknown_error[i];
- }
- error_message = result[0];
- free(result[0]); // Никаких утечек памяти в мою смену
- }
- return error_message;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement