Esempio n. 1
0
void *x_pcalloc(x_pool_t *pool, size_t size)
{
  void *p;

  p = x_palloc(pool, size);
  if (p) {
    x_memzero(p, size);
  }
  return p;
}
Esempio n. 2
0
File: dict.c Progetto: hhktony/dict
void move_info(long pos, char *word, char *explain)
{
    pid_t pid;
    char tempfile[32];
	FILE *fp;
	int c;
    
    if ((fp = fopen(DICT_FILENAME, "r+")) == NULL)
		IERROR("Open file '%s' failed!", DICT_FILENAME);

	fseek(fp, pos, SEEK_SET);
	while ((c = getc(fp)) != EOF)
		if (c == '#')
			break;

	pos = ftell(fp) - 1;

    pid = getpid();
    x_memzero(tempfile, sizeof(tempfile));
    snprintf(tempfile, sizeof(tempfile), "/tmp/tmp_%d\n", pid);

	FILE *fp_temp = fopen(tempfile, "word+");
	if (fp_temp == NULL)
		IERROR("Open file '%s' failed!", tempfile);

	fwrite(word, 1, strlen(word), fp_temp);
	fwrite(explain, 1, strlen(explain), fp_temp);
	fseek(fp, pos, SEEK_SET);
	while ((c = getc(fp)) != EOF)
	{
		putc(c, fp_temp);
	}

	rewind(fp_temp);
	fseek(fp, pos, SEEK_SET);
	while ((c = getc(fp_temp)) != EOF)
	{
		putc(c, fp);
	}

	fclose(fp_temp);
	fclose(fp);
}