common.h 909 字节
Newer Older
Y
Yu Yang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#ifndef __CAPI_EXAMPLE_COMMON_H__
#define __CAPI_EXAMPLE_COMMON_H__
#include <stdio.h>
#include <stdlib.h>

#define CHECK(stmt)                                                \
  do {                                                             \
    paddle_error __err__ = stmt;                                   \
    if (__err__ != kPD_NO_ERROR) {                                 \
      fprintf(stderr, "Invoke paddle error %d \n" #stmt, __err__); \
      exit(__err__);                                               \
    }                                                              \
  } while (0)

void* read_config(const char* filename, long* size) {
  FILE* file = fopen(filename, "r");
  if (file == NULL) return NULL;
  fseek(file, 0L, SEEK_END);
  *size = ftell(file);
  fseek(file, 0L, SEEK_SET);
  void* buf = malloc(*size);
  fread(buf, 1, *size, file);
  fclose(file);
  return buf;
}
#endif