utility/tpmc.c
/* TPM error check and reporting.  Returns 0 if |result| is 0 (TPM_SUCCESS).
 * Otherwise looks up a TPM error in the error table and prints the error if
 * found.  Then returns min(result, OTHER_ERROR) since some error codes, such
 * as TPM_E_RETRY, do not fit in a byte.
 */
TPM error check and reporting.  Returns 0 if |result| is 0 (TPM_SUCCESS).
Otherwise looks up a TPM error in the error table and prints the error if
found.  Then returns min(result, OTHER_ERROR) since some error codes, such
as TPM_E_RETRY, do not fit in a byte.
TPM error check and reporting . Returns 0 if |result| is 0 ( TPM_SUCCESS ) . Otherwise looks up a TPM error in the error table and prints the error if found . Then returns min ( result OTHER_ERROR ) since some error codes such as TPM_E_RETRY do not fit in a byte .
static uint8_t ErrorCheck(uint32_t result, const char* cmd) {
  uint8_t exit_code = result > OTHER_ERROR ? OTHER_ERROR : result;
  if (result == 0) {
    return 0;
  } else {
    int i;
    int n = sizeof(tpm_error_table) / sizeof(tpm_error_table[0]);
    fprintf(stderr, "command \"%s\" failed with code %#x\n", cmd, result);
    for (i = 0; i < n; i++) {
      if (tpm_error_table[i].code == result) {
        fprintf(stderr, "%s\n%s\n", tpm_error_table[i].name,
                tpm_error_table[i].description);
        return exit_code;
      }
    }
    fprintf(stderr, "the TPM error code is unknown to this program\n");
    return exit_code;
  }
}
static uint8_t ErrorCheck ( uint32_t result , const char * cmd ) { uint8_t exit_code = result > OTHER_ERROR ? OTHER_ERROR : result ; if ( result == 0 ) { return 0 ; } else { int i ; int n = sizeof ( tpm_error_table ) / sizeof ( tpm_error_table [ 0 ] ) ; fprintf ( stderr , " \" \" \n " , cmd , result ) ; for ( i = 0 ; i < n ; i ++ ) { if ( tpm_error_table [ i ] . code == result ) { fprintf ( stderr , " \n \n " , tpm_error_table [ i ] . name , tpm_error_table [ i ] . description ) ; return exit_code ; } } fprintf ( stderr , " \n " ) ; return exit_code ; } }
TPM error check and reporting.
TPM error check and reporting .