emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] Changes to emacs/lib-src/update-game-score.c


From: Colin Walters
Subject: [Emacs-diffs] Changes to emacs/lib-src/update-game-score.c
Date: Wed, 31 Jul 2002 21:31:44 -0400

Index: emacs/lib-src/update-game-score.c
diff -c emacs/lib-src/update-game-score.c:1.10 
emacs/lib-src/update-game-score.c:1.11
*** emacs/lib-src/update-game-score.c:1.10      Mon Apr 29 18:49:00 2002
--- emacs/lib-src/update-game-score.c   Wed Jul 31 21:31:44 2002
***************
*** 53,60 ****
  #define __attribute__(x) 
  #endif
  
  int
! usage(int err)
  {
    fprintf(stdout, "Usage: update-game-score [-m MAX ] [ -r ] game/scorefile 
SCORE DATA\n");
    fprintf(stdout, "       update-game-score -h\n");
--- 53,68 ----
  #define __attribute__(x) 
  #endif
  
+ /* Declare the prototype for a general external function.  */
+ #if defined (PROTOTYPES) || defined (WINDOWSNT)
+ #define P_(proto) proto
+ #else
+ #define P_(proto) ()
+ #endif
+ 
  int
! usage(err)
!      int err;
  {
    fprintf(stdout, "Usage: update-game-score [-m MAX ] [ -r ] game/scorefile 
SCORE DATA\n");
    fprintf(stdout, "       update-game-score -h\n");
***************
*** 66,74 ****
  }
  
  int
! lock_file(const char *filename, void **state);
  int
! unlock_file(const char *filename, void *state);
  
  struct score_entry
  {
--- 74,82 ----
  }
  
  int
! lock_file P_((const char *filename, void **state));
  int
! unlock_file P_((const char *filename, void *state));
  
  struct score_entry
  {
***************
*** 78,104 ****
  };
  
  int
! read_scores(const char *filename, struct score_entry **scores,
!           int *count);
  int
! push_score(struct score_entry **scores, int *count,
!          int newscore, char *username, char *newdata);
  void
! sort_scores(struct score_entry *scores, int count, int reverse);
  int
! write_scores(const char *filename, const struct score_entry *scores,
!            int count);
  
! void lose(const char *msg, ...)
!      __attribute__ ((format (printf,1,0), noreturn));
  
! void lose(const char *msg, ...)
  {
!     va_list ap;
!     va_start(ap, msg);
!     vfprintf(stderr, msg, ap);
!     va_end(ap);
!     exit(1);
  }
  
  char *
--- 86,120 ----
  };
  
  int
! read_scores P_((const char *filename, struct score_entry **scores,
!               int *count));
  int
! push_score P_((struct score_entry **scores, int *count,
!              int newscore, char *username, char *newdata));
  void
! sort_scores P_((struct score_entry *scores, int count, int reverse));
  int
! write_scores P_((const char *filename, const struct score_entry *scores,
!                int count));
! 
! void lose P_((const char *msg))
!      __attribute__ ((noreturn));
! 
! void lose(msg)
!      const char *msg;
! {
!   fprintf(stderr, "%s\n", msg);
!   exit(1);
! }
  
! void lose_syserr P_((const char *msg))
!      __attribute__ ((noreturn));
  
! void lose_syserr(msg)
!      const char *msg;
  {
!   fprintf(stderr, "%s: %s\n", msg, strerror(errno));
!   exit(1);
  }
  
  char *
***************
*** 123,145 ****
  }
  
  char *
! get_prefix(int running_suid, char *user_prefix)
  {
    if (!running_suid && user_prefix == NULL)
!     lose("Not using a shared game directory, and no prefix given.\n");
    if (running_suid)
      {
  #ifdef HAVE_SHARED_GAME_DIR
        return HAVE_SHARED_GAME_DIR;
  #else
!       lose("This program was compiled without HAVE_SHARED_GAME_DIR,\n and 
should not be suid.\n");
  #endif
      }
    return user_prefix;
  }
  
  int
! main(int argc, char **argv)
  {
    int c, running_suid;
    void *lockstate;
--- 139,165 ----
  }
  
  char *
! get_prefix(running_suid, user_prefix)
!      int running_suid;
!      char *user_prefix;
  {
    if (!running_suid && user_prefix == NULL)
!     lose("Not using a shared game directory, and no prefix given.");
    if (running_suid)
      {
  #ifdef HAVE_SHARED_GAME_DIR
        return HAVE_SHARED_GAME_DIR;
  #else
!       lose("This program was compiled without HAVE_SHARED_GAME_DIR,\n and 
should not be suid.");
  #endif
      }
    return user_prefix;
  }
  
  int
! main(argc, argv)
!      int argc;
!      char **argv;
  {
    int c, running_suid;
    void *lockstate;
***************
*** 181,187 ****
  
    scorefile = malloc(strlen(prefix) + strlen(argv[optind]) + 2);
    if (!scorefile)
!     lose("Couldn't create score file name: %s\n", strerror(errno));
  
    strcpy(scorefile, prefix);
    strcat(scorefile, "/");
--- 201,207 ----
  
    scorefile = malloc(strlen(prefix) + strlen(argv[optind]) + 2);
    if (!scorefile)
!     lose_syserr("Couldn't allocate score file");
  
    strcpy(scorefile, prefix);
    strcat(scorefile, "/");
***************
*** 192,210 ****
      newdata[MAX_DATA_LEN] = '\0';
  
    if ((user_id = get_user_id()) == NULL)
!     lose("Couldn't determine user id: %s\n", strerror(errno));
    
    if (stat(scorefile, &buf) < 0)
!     lose("Failed to access scores file \"%s\": %s\n", scorefile,
!        strerror(errno));
    if (lock_file(scorefile, &lockstate) < 0)
!       lose("Failed to lock scores file \"%s\": %s\n",
!          scorefile, strerror(errno));
    if (read_scores(scorefile, &scores, &scorecount) < 0)
      {
        unlock_file(scorefile, lockstate);
!       lose("Failed to read scores file \"%s\": %s\n", scorefile,
!          strerror(errno));
      }
    push_score(&scores, &scorecount, newscore, user_id, newdata);
    /* Limit the number of scores.  If we're using reverse sorting, then
--- 212,229 ----
      newdata[MAX_DATA_LEN] = '\0';
  
    if ((user_id = get_user_id()) == NULL)
!     lose_syserr("Couldn't determine user id");
    
    if (stat(scorefile, &buf) < 0)
!     lose_syserr("Failed to access scores file");
!               
    if (lock_file(scorefile, &lockstate) < 0)
!     lose_syserr("Failed to lock scores file");
!                 
    if (read_scores(scorefile, &scores, &scorecount) < 0)
      {
        unlock_file(scorefile, lockstate);
!       lose_syserr("Failed to read scores file");
      }
    push_score(&scores, &scorecount, newscore, user_id, newdata);
    /* Limit the number of scores.  If we're using reverse sorting, then
***************
*** 219,233 ****
    if (write_scores(scorefile, scores, scorecount) < 0)
      {
        unlock_file(scorefile, lockstate);
!       lose("Failed to write scores file \"%s\": %s\n", scorefile,
!          strerror(errno));
      }
    unlock_file(scorefile, lockstate);
    exit(0);
  }
  
  int
! read_score(FILE *f, struct score_entry *score)
  {
    int c;
    if (feof(f))
--- 238,253 ----
    if (write_scores(scorefile, scores, scorecount) < 0)
      {
        unlock_file(scorefile, lockstate);
!       lose_syserr("Failed to write scores file");
      }
    unlock_file(scorefile, lockstate);
    exit(0);
  }
  
  int
! read_score(f, score)
!      FILE *f;
!      struct score_entry *score;
  {
    int c;
    if (feof(f))
***************
*** 311,318 ****
  }
  
  int
! read_scores(const char *filename, struct score_entry **scores,
!           int *count)
  {
    int readval, scorecount, cursize;
    struct score_entry *ret;
--- 331,340 ----
  }
  
  int
! read_scores(filename, scores, count)
!      const char *filename;
!      struct score_entry **scores;
!      int *count;
  {
    int readval, scorecount, cursize;
    struct score_entry *ret;
***************
*** 343,349 ****
  }
  
  int
! score_compare(const void *a, const void *b)
  {
    const struct score_entry *sa = (const struct score_entry *) a;
    const struct score_entry *sb = (const struct score_entry *) b;
--- 365,373 ----
  }
  
  int
! score_compare(a, b)
!      const void *a;
!      const void *b;
  {
    const struct score_entry *sa = (const struct score_entry *) a;
    const struct score_entry *sb = (const struct score_entry *) b;
***************
*** 351,357 ****
  }
  
  int
! score_compare_reverse(const void *a, const void *b)
  {
    const struct score_entry *sa = (const struct score_entry *) a;
    const struct score_entry *sb = (const struct score_entry *) b;
--- 375,383 ----
  }
  
  int
! score_compare_reverse(a, b)
!      const void *a;
!      const void *b;
  {
    const struct score_entry *sa = (const struct score_entry *) a;
    const struct score_entry *sb = (const struct score_entry *) b;
***************
*** 359,366 ****
  }
  
  int
! push_score(struct score_entry **scores, int *count,
!          int newscore, char *username, char *newdata) 
  {
   struct score_entry *newscores = realloc(*scores,
                                         sizeof(struct score_entry) * ((*count) 
+ 1));
--- 385,395 ----
  }
  
  int
! push_score(scores, count, newscore, username, newdata) 
!      struct score_entry **scores;
!      int *count; int newscore;
!      char *username;
!      char *newdata;
  {
   struct score_entry *newscores = realloc(*scores,
                                         sizeof(struct score_entry) * ((*count) 
+ 1));
***************
*** 375,389 ****
  }
    
  void
! sort_scores(struct score_entry *scores, int count, int reverse)
  {
    qsort(scores, count, sizeof(struct score_entry),
        reverse ? score_compare_reverse : score_compare);
  }
  
  int
! write_scores(const char *filename, const struct score_entry *scores,
!            int count)
  {
    FILE *f;  
    int i;
--- 404,423 ----
  }
    
  void
! sort_scores(scores, count, reverse)
!      struct score_entry *scores;
!      int count;
!      int reverse; 
  {
    qsort(scores, count, sizeof(struct score_entry),
        reverse ? score_compare_reverse : score_compare);
  }
  
  int
! write_scores(filename, scores, count)
!      const char *filename;
!      const struct score_entry * scores;
!      int count; 
  {
    FILE *f;  
    int i;
***************
*** 410,418 ****
      return -1;
    return 0;
  }
! 
  int
! lock_file(const char *filename, void **state)
  {
    int fd;
    struct stat buf;
--- 444,454 ----
      return -1;
    return 0;
  }
!   
  int
! lock_file(filename, state)
!   const char *filename;
!   void **state;
  {
    int fd;
    struct stat buf;
***************
*** 450,458 ****
    close(fd);
    return 0;
  }
! 
  int
! unlock_file(const char *filename, void *state)
  {
    char *lockpath = (char *) state;
    int ret = unlink(lockpath);
--- 486,496 ----
    close(fd);
    return 0;
  }
!  
  int
! unlock_file(filename, state)
!   const char *filename;
!  void *state;
  {
    char *lockpath = (char *) state;
    int ret = unlink(lockpath);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]