/** * Find closest error description * * @v errno Error number * @ret errortab Error description, or NULL * * */ static struct errortab * find_closest_error ( int errno ) { struct errortab *errortab; /* First, look for an exact match */ if ( ( errortab = find_error ( errno ) ) != NULL ) return errortab; /* Second, try masking off the iPXE-specific bit and seeing if * we have an entry for the generic POSIX error message. */ if ( ( errortab = find_error ( errno & 0x7f0000ff ) ) != NULL ) return errortab; return NULL; }
char * scsi_error(int code) { static char text[80], *cp; if (code == 0) return "No error"; if (code == ComeAgain) return "Busy"; switch (ErrorClass(code)) { case ErrorClass(SenseKey): return senseTab[code & 0x0F]; case ErrorClass(ExtendedError): switch (senseMode) { case TDC3600: sprintf(text, "Error code: %s", find_error(tdc3600ercd, ErrorCode(code))); break; default: sprintf(text, "Additional sense code: %02X", ErrorCode(code)); } break; case ErrorClass(StatusError): sprintf(text, "Target status: %s", find_error(targetStatusTab, ErrorCode(code))); break; case ErrorClass(DriverError): sprintf(text, "Operation not implemented"); break; case ErrorClass(SystemError): cp = strerror(ErrorCode(code)); if (cp) strcpy(text, cp); else sprintf(text, "System error: %u", ErrorCode(code)); break; case ErrorClass(HostError): sprintf(text, "Host adapter error: %u", ErrorCode(code)); break; default: sprintf(text, "Other error: %04X", code); break; } return text; }
void find_user() { FILE* fd1 = fopen("username.txt", "r");//open username.txt char user[USER_LEN]; char pswd[PSWD_LEN]; char underscore[3] = "_\0"; char *username; //retrieves username and password printf("Please type in your username:\n"); fgets(user, USER_LEN, stdin); printf("Please type in your password:\n"); fgets(pswd, PSWD_LEN, stdin); //printf("user: %s\n", user); //printf("pswd: %s\n", pswd); if (find_error(user, pswd) == 1) { username = calloc(strlen(user) + strlen(pswd) + 1 + 1, sizeof(char));//1 is for the underscore and the other is for the null char strcat(username, user); char *line = (char *)calloc(strlen(user) + strlen(pswd) + strlen(underscore) + 1, sizeof(char)); line = strsep(&username, "\n"); strcat(line, underscore); strcat(line, pswd); printf("line: %s\n", line); char *buffer = (char *)malloc(BUFFER_LEN*sizeof(char)); fread(buffer, sizeof(char), BUFFER_LEN, fd1); //printf("strlen(buffer) = %lu\n", strlen(buffer)); printf("buffer: %s\n", buffer); if (strstr(buffer, line) == NULL) printf("find_user() returned NULL. You typed incorrectly.\n"); else printf("HUZZAH. You are a valid user! \n"); buffer = ""; printf("buffer after fread/fwrite: %s\n", buffer); } else if (find_error(user, pswd) == 0) printf("final_errpr returned 0\n"); else printf("Unknown error in find_user\n"); }