Beispiel #1
0
/* 
 * get information on the given slot
 */
static void slot_info(char *info_buf, size_t info_bufsiz, size_t slot_id) {
    char buf[256];
    int fd;

    /* get slot file path */
    build_slot_path(buf, 256, slot_id);

    /* attempt to open slot */
    if ((fd = open(buf, O_RDONLY)) >= 0)
    {
        /* this slot has a some data in it, read it */
        if (read(fd, buf, 20) > 0)
        {
            buf[20] = '\0';
            snprintf(info_buf, info_bufsiz, "%zud. %s", slot_id + 1, buf);
        }
        else
            snprintf(info_buf, info_bufsiz, "%zud. ERROR", slot_id + 1);

        close(fd);
    }
    else
    {
        /* if we couldn't open the file, then the slot is empty */
        snprintf(info_buf, info_bufsiz, "%zu. %s", slot_id + 1, "<Empty>");
    }
}
Beispiel #2
0
/*
 * do_slot - load or save game data in the given slot
 *
 * Returns true on success and false on failure.
 */
static bool do_slot(size_t slot_id, bool is_load) {
  char *path_buf;
  bool res;
  path_buf=(char *)malloc(256);

  /* build slot filename*/
  build_slot_path(path_buf, 256, slot_id);
  printf("Path : %s\n",path_buf);

  /* load/save file */
  res = do_file(path_buf/*, desc_buf*/, is_load);
  free(path_buf);
  return  res;
}
Beispiel #3
0
/*
 * do_slot - load or save game data in the given slot
 *
 * Returns true on success and false on failure.
 */
static bool do_slot(size_t slot_id, bool is_load) {
    char path_buf[256], desc_buf[20];
  
    /* build slot filename, clear desc buf */
    build_slot_path(path_buf, 256, slot_id);
    memset(desc_buf, 0, 20);

    /* if we're saving to a slot, then get a brief description */
    if (!is_load)
        if ( (rb->kbd_input(desc_buf, 20) < 0) || !strlen(desc_buf) )
        {
            strlcpy(desc_buf, "Untitled", 20);
        }

    /* load/save file */
    return do_file(path_buf, desc_buf, is_load);
}
Beispiel #4
0
/*
 * get information on the given slot
 */
static void slot_info(char *info_buf, size_t info_bufsiz, size_t slot_id) {
  char * buf;
  int fd;
  buf=(char *)malloc(256);

  /* get slot file path */
  build_slot_path(buf, 256, slot_id);

  /* attempt to open slot */
  if ((fd = open(buf, O_RDONLY)) >= 0) {
    snprintf(info_buf, info_bufsiz, "%2d. State Saved", slot_id + 1);
    close(fd);
  } else {
    /* if we couldn't open the file, then the slot is empty */
    snprintf(info_buf, info_bufsiz, "%2d. Empty", slot_id + 1);
    free(buf);
  }
}