jimi-wzq
2020-07-28 6bfcc3964b3a14105683c723a61d354cefc95b0e
test/test.c
@@ -1,35 +1,15 @@
#include "test.h"
#define MKEY 0x2222
int testmatshm() {
#include "usg_common.h"
#include "usg_typedef.h"
  int shmid = -1;
  void *shmp;
  shmid = shmget(MKEY, 1024, IPC_CREAT | IPC_EXCL | OBJ_PERMS);
  if (shmid == -1 && errno == EEXIST) {
    printf("first create\n");
    shmid = shmget(MKEY, 0, 0);
  }
  if (shmid == -1)
    err_exit(errno, "testmatshm shmget");
  shmp = shmat(shmid, NULL, 0);
int test(char *src, int size) {
   int i = strlen(src);
   char dest[size];
   strncpy(dest, src, size);
   puts(dest);
   return i;
}
typedef struct buf_t { char buf[7]; } buf_t;
void test(int size) {
  char buf[size];
  printf("size = %d\n", sizeof(buf));
}
char msg[10];
int main() {
  // testmatshm();
  // testmatshm();
  // sleep(60);
  // printf("size = %d, msg = %d\n", sizeof(buf_t), sizeof(msg));
  test(12);
   char *str = "hello";
   int r = test(str, strlen(str));
   printf("%d\n", r);
}