コード例 #1
0
ファイル: faketime.c プロジェクト: madscientist/libfaketime
/* Contributed by Philipp Hachtmann in version 0.6 */
int __lxstat64 (int ver, const char *path, struct stat64 *buf){
  static int (*real_lstat) (int, const char *, struct stat64 *);
  static int has_real_lstat = 0;

  SINGLE_IF(has_real_lstat==0)
    real_lstat = NULL;
    real_lstat = dlsym(RTLD_NEXT, "__lxstat64");
    if (dlerror() == NULL) {
      has_real_lstat = 1;
    }
  END_SINGLE_IF
  if (!has_real_lstat) {  /* dlsym() failed */
#ifdef DEBUG
    (void) fprintf(stderr, "faketime problem: original lstat() not found.\n");
#endif
    return -1; /* propagate error to caller */
  }

  int result = real_lstat(ver, path, buf);
  if (result == -1){
    return -1;
  }

  if (buf != NULL){
    if (!fake_stat_disabled) {
      buf->st_ctime = fake_time(&(buf->st_ctime));
      buf->st_atime = fake_time(&(buf->st_atime));
      buf->st_mtime = fake_time(&(buf->st_mtime));
    }
  }
  return result;
}
コード例 #2
0
ファイル: faketime.c プロジェクト: madscientist/libfaketime
int __fxstatat64 (int ver, int fildes, const char *filename, struct stat64 *buf, int flag) {
  static int (*real_fstatat64)(int, int , const char *, struct stat64 *, int);
  static int has_real_fstatat64=0;

  SINGLE_IF(has_real_fstatat64==0)
    real_fstatat64 = NULL;
    real_fstatat64 = dlsym(RTLD_NEXT, "__fxstatat64");
    if (dlerror() == NULL) {
      has_real_fstatat64 = 1;
    }
  END_SINGLE_IF
  if (!has_real_fstatat64) {  /* dlsym() failed */
#ifdef DEBUG
    (void) fprintf(stderr, "faketime problem: original fstatat64() not found.\n");
#endif
    return -1; /* propagate error to caller */
  }

  int result = real_fstatat64(ver, fildes, filename, buf, flag);
  if (result == -1){
    return -1;
  }

  if (buf != NULL){
    if (!fake_stat_disabled) {
      buf->st_ctime = fake_time(&(buf->st_ctime));
      buf->st_atime = fake_time(&(buf->st_atime));
      buf->st_mtime = fake_time(&(buf->st_mtime));
    }
  }
  return result;
}
コード例 #3
0
ファイル: faketime.c プロジェクト: madscientist/libfaketime
int fake_gettimeofday(struct timeval *tv, void *tz) {
    time_t temp_tt = tv->tv_sec;

    tv->tv_sec = fake_time(&temp_tt);

    return 0;
}
コード例 #4
0
ファイル: faketime.c プロジェクト: madscientist/libfaketime
int fake_ftime(struct timeb *tp) {
    time_t temp_tt = tp->time;

    tp->time = fake_time(&temp_tt);

    return 0; /* always returns 0, see manpage */
}
コード例 #5
0
ファイル: death.c プロジェクト: artes-liberales/FAangband
/**
 * Handle character death
 */
void death_screen(void)
{
    const region area = { 51, 2, 0, N_ELEMENTS(death_actions) };

    /* Dump bones file */
    make_bones();

    /* Handle retirement */
    if (p_ptr->total_winner)
	kingly();

    /* Save dead player */
    if (!old_save())
    {
	msg_print("death save failed!");
	message_flush();
    }

    /* Get time of death */
#ifdef _WIN32_WCE
    {
	unsigned long fake_time(unsigned long *fake_time_t);
	fake_time(&death_time);
    }
#else
    (void) time(&death_time);
#endif

    /* You are dead */
    print_tomb();

    /* Hack - Know everything upon death */
    death_knowledge();

    /* Enter player in high score list */
    enter_score(&death_time);

    /* Flush all input keys */
    flush();

    /* Flush messages */
    msg_print(NULL);

    if (!death_menu)
    {
	death_menu = menu_new_action(death_actions,
				     N_ELEMENTS(death_actions));

	death_menu->flags = MN_CASELESS_TAGS;
    }

    menu_layout(death_menu, &area);

    do
    {
	menu_select(death_menu, 0);
    } while (!get_check("Do you want to quit? "));
}
コード例 #6
0
ファイル: faketime.c プロジェクト: madscientist/libfaketime
int fake_clock_gettime(clockid_t clk_id, struct timespec *tp) {
    time_t temp_tt = tp->tv_sec;

    /* Fake only if the call is realtime clock related */
    if (clk_id == CLOCK_REALTIME) {
        tp->tv_sec = fake_time(&temp_tt);
    }

    return 0;
}
コード例 #7
0
ファイル: faketime.c プロジェクト: madscientist/libfaketime
time_t time(time_t *time_tptr) {
    time_t result;
    time_t null_dummy;
    if (time_tptr == NULL) {
        time_tptr = &null_dummy;
        /* (void) fprintf(stderr, "NULL pointer caught in time().\n"); */
    }
    result = _ftpl_time(time_tptr);
    if (result == ((time_t) -1)) return result;

    /* pass the real current time to our faking version, overwriting it */
    result = fake_time(time_tptr);

    /* return the result to the caller */
    return result;
}
コード例 #8
0
ファイル: death.c プロジェクト: artes-liberales/FAangband
/**
 * Display a "tomb-stone"
 */
static void print_tomb(void)
{
    cptr p;

    int offset = 12;

    char tmp[160];

    char buf[1024];

    ang_file *fp;

#ifdef _WIN32_WCE
    time_t ct = fake_time((time_t) 0);
#else
    time_t ct = time((time_t) 0);
#endif

    bool boat = ((p_ptr->total_winner) && (player_has(PF_ELVEN)));
    bool tree = ((p_ptr->total_winner)
		 && (player_has(PF_WOODEN) || player_has(PF_DIVINE)));

    /* Clear screen */
    Term_clear();

    /* Build the filename */
    if (tree)
	path_build(buf, 1024, ANGBAND_DIR_FILE, "tree.txt");
    else if (boat)
	path_build(buf, 1024, ANGBAND_DIR_FILE, "boat.txt");
    else
	path_build(buf, 1024, ANGBAND_DIR_FILE, "dead.txt");

    /* Open the News file */
    fp = file_open(buf, MODE_READ, FTYPE_TEXT);

    /* Dump */
    if (fp) {
	int i, y, x;

	byte a = 0;
	char c = ' ';

	bool okay = TRUE;

	int len;


	/* Load the screen */
	for (y = 0; okay; y++) {
	    /* Get a line of data */
	    if (!file_getl(fp, buf, 1024))
		okay = FALSE;

	    /* Stop on blank line */
	    if (!buf[0])
		break;

	    /* Get the width */
	    len = strlen(buf);

	    /* XXX Restrict to current screen size */
	    if (len >= Term->wid)
		len = Term->wid;

	    /* Show each row */
	    for (x = 0; x < len; x++) {
		/* Put the attr/char */
		Term_draw(x, y, TERM_WHITE, buf[x]);
	    }
	}

	/* Get the blank line */
	/* if (my_fgets(fp, buf, 1024)) okay = FALSE; */


	/* Load the screen */
	for (y = 0; okay; y++) {
	    /* Get a line of data */
	    if (!file_getl(fp, buf, 1024))
		okay = FALSE;

	    /* Stop on blank line */
	    if (!buf[0])
		break;

	    /* Get the width */
	    len = strlen(buf);

	    /* XXX Restrict to current screen size */
	    if (len >= Term->wid)
		len = Term->wid;

	    /* Show each row */
	    for (x = 0; x < len; x++) {
		/* Get the attr/char */
		(void) (Term_what(x, y, &a, &c));

		/* Look up the attr */
		for (i = 0; i < 16; i++) {
		    /* Use attr matches */
		    if (hack[i] == buf[x])
			a = i;
		}

		/* Put the attr/char */
		Term_draw(x, y, a, c);
	    }

	    /* Place the cursor */
	    Term_gotoxy(x, y);

	}


	/* Get the blank line */
	/* if (my_fgets(fp, buf, 1024)) okay = FALSE; */


	/* Close it */
	file_close(fp);
    }

    /* King or Queen */
    if (p_ptr->total_winner || (p_ptr->lev > PY_MAX_LEVEL)) {
	p = "Magnificent";
    }

    /* Normal */
    else {
	p = cp_ptr->title[(p_ptr->lev - 1) / 5];
    }

    /* Set offset */
    offset = 11;

    center_string(buf, op_ptr->full_name);
    put_str(buf, 6, offset);

    center_string(buf, "the");
    put_str(buf, 7, offset);

    center_string(buf, p);
    put_str(buf, 8, offset);


    center_string(buf, cp_ptr->name);
    put_str(buf, 10, offset);

    sprintf(tmp, "Level: %d", (int) p_ptr->lev);
    center_string(buf, tmp);
    put_str(buf, 11, offset);

    sprintf(tmp, "Exp: %ld", (long) p_ptr->exp);
    center_string(buf, tmp);
    put_str(buf, 12, offset);

    sprintf(tmp, "AU: %ld", (long) p_ptr->au);
    center_string(buf, tmp);
    put_str(buf, 13, offset);

    if (p_ptr->depth)
	sprintf(tmp, "Killed in %s level %d",
		locality_name[stage_map[p_ptr->stage][LOCALITY]], p_ptr->depth);
    else if (boat)
	sprintf(tmp, "Sailed victorious to Aman.");
    else if (tree)
	sprintf(tmp, "Retired to Fangorn Forest.");
    else
	sprintf(tmp, "Killed in %s town",
		locality_name[stage_map[p_ptr->stage][LOCALITY]]);
    center_string(buf, tmp);
    put_str(buf, 14, offset);

    if (!(boat || tree)) {
	sprintf(tmp, "by %s.", p_ptr->died_from);
	center_string(buf, tmp);
	put_str(buf, 15, offset);
    }
#ifdef _WIN32_WCE
    {
	char *fake_ctime(const unsigned long *fake_time_t);
	sprintf(tmp, "%-.24s", fake_ctime(&ct));
    }
#else
    sprintf(tmp, "%-.24s", ctime(&ct));
#endif
    center_string(buf, tmp);
    put_str(buf, 17, offset);
}