Hi there,

creat(3) "is made obsolete by: open(2)". The diff below replaces all
occurrences of

creat(path, mode)

with

open(path, O_CREAT | O_TRUNC | O_WRONLY, mode)

in games.

Cheers,
Frederic


Index: backgammon/common_source/save.c
===================================================================
RCS file: /cvs/src/games/backgammon/common_source/save.c,v
retrieving revision 1.12
diff -u -p -r1.12 save.c
--- backgammon/common_source/save.c     26 Jun 2015 19:18:03 -0000      1.12
+++ backgammon/common_source/save.c     10 Nov 2015 19:31:32 -0000
@@ -86,7 +86,9 @@ save(n)
                }
                *fs = '\0';
                if ((fdesc = open(fname, O_RDWR)) == -1 && errno == ENOENT) {
-                       if ((fdesc = creat(fname, 0600)) != -1)
+                       if ((fdesc = open(fname,
+                                         O_CREAT | O_TRUNC | O_WRONLY,
+                                         0600)) != -1)
                                break;
                }
                if (fdesc != -1) {
@@ -97,7 +99,9 @@ save(n)
                        close(fdesc);
                        if (yorn(0)) {
                                unlink(fname);
-                               fdesc = creat(fname, 0600);
+                               fdesc = open(fname,
+                                            O_CREAT | O_TRUNC | O_WRONLY,
+                                            0600);
                                break;
                        } else {
                                cflag = 1;
Index: hack/hack.bones.c
===================================================================
RCS file: /cvs/src/games/hack/hack.bones.c,v
retrieving revision 1.8
diff -u -p -r1.8 hack.bones.c
--- hack/hack.bones.c   27 Oct 2009 23:59:25 -0000      1.8
+++ hack/hack.bones.c   10 Nov 2015 19:31:32 -0000
@@ -129,7 +129,7 @@ savebones()
                        otmp->cursed = 1;    /* flag as gotten from a ghost */
                }
        }
-       if((fd = creat(bones, FMASK)) < 0) return;
+       if((fd = open(bones, O_CREAT | O_TRUNC | O_WRONLY, FMASK)) < 0) return;
        savelev(fd,dlevel);
        (void) close(fd);
 }
Index: hack/hack.do.c
===================================================================
RCS file: /cvs/src/games/hack/hack.do.c,v
retrieving revision 1.8
diff -u -p -r1.8 hack.do.c
--- hack/hack.do.c      11 Mar 2014 08:05:15 -0000      1.8
+++ hack/hack.do.c      10 Nov 2015 19:31:32 -0000
@@ -193,7 +193,7 @@ goto_level(int newlevel, boolean at_stai
        if(newlevel == dlevel) return;        /* this can happen */

        glo(dlevel);
-       fd = creat(lock, FMASK);
+       fd = open(lock, O_CREAT | O_TRUNC | O_WRONLY, FMASK);
        if(fd < 0) {
                /*
                 * This is not quite impossible: e.g., we may have
Index: hack/hack.save.c
===================================================================
RCS file: /cvs/src/games/hack/hack.save.c,v
retrieving revision 1.11
diff -u -p -r1.11 hack.save.c
--- hack/hack.save.c    11 Mar 2014 08:05:15 -0000      1.11
+++ hack/hack.save.c    10 Nov 2015 19:31:32 -0000
@@ -100,7 +100,7 @@ dosave0(int hu)

        (void) signal(SIGHUP, SIG_IGN);
        (void) signal(SIGINT, SIG_IGN);
-       if((fd = creat(SAVEF, FMASK)) < 0) {
+       if((fd = open(SAVEF, O_CREAT | O_TRUNC | O_WRONLY, FMASK)) < 0) {
                if(!hu) pline("Cannot open save file. (Continue or Quit)");
                (void) unlink(SAVEF);           /* ab@unido */
                return(0);
@@ -192,7 +192,7 @@ dorecover(int fd)
                        break;
                getlev(fd, 0, tmp);
                glo(tmp);
-               if((nfd = creat(lock, FMASK)) < 0)
+               if((nfd = open(lock, O_CREAT | O_TRUNC | O_WRONLY, FMASK)) < 0)
                        panic("Cannot open temp file %s!\n", lock);
                savelev(nfd,tmp);
                (void) close(nfd);
Index: hack/hack.unix.c
===================================================================
RCS file: /cvs/src/games/hack/hack.unix.c,v
retrieving revision 1.15
diff -u -p -r1.15 hack.unix.c
--- hack/hack.unix.c    16 Nov 2014 04:49:48 -0000      1.15
+++ hack/hack.unix.c    10 Nov 2015 19:31:32 -0000
@@ -286,7 +286,7 @@ getlock()
        error(locknum ? "Too many hacks running now."
                      : "There is a game in progress under your name.");
 gotlock:
-       fd = creat(lock, FMASK);
+       fd = open(lock, O_CREAT | O_TRUNC | O_WRONLY, FMASK);
        if(unlink(LLOCK) == -1)
                error("Cannot unlink %s.", LLOCK);
        if(fd == -1) {
@@ -452,7 +452,7 @@ mdrush(struct monst *md, boolean away)
                                md->my = fy;
                            }
                            break;
-                       }
+                       }
                }
                tmp_at(-1,-1);                  /* close call */
        }
Index: mille/save.c
===================================================================
RCS file: /cvs/src/games/mille/save.c,v
retrieving revision 1.8
diff -u -p -r1.8 save.c
--- mille/save.c        27 Oct 2009 23:59:26 -0000      1.8
+++ mille/save.c        10 Nov 2015 19:31:32 -0000
@@ -100,7 +100,7 @@ over:
            && getyn(OVERWRITEFILEPROMPT) == FALSE))
                return FALSE;

-       if ((outf = creat(buf, 0644)) < 0) {
+       if ((outf = open(buf, O_CREAT | O_TRUNC | O_WRONLY, 0644)) < 0) {
                error(strerror(errno));
                return FALSE;
        }
Index: trek/dumpgame.c
===================================================================
RCS file: /cvs/src/games/trek/dumpgame.c,v
retrieving revision 1.9
diff -u -p -r1.9 dumpgame.c
--- trek/dumpgame.c     27 Oct 2009 23:59:27 -0000      1.9
+++ trek/dumpgame.c     10 Nov 2015 19:31:32 -0000
@@ -81,7 +81,7 @@ dumpgame(v)
        struct dump     *d;
        int             i;

-       if ((fd = creat("trek.dump", 0644)) < 0)
+       if ((fd = open("trek.dump", O_CREAT | O_TRUNC | O_WRONLY, 0644)) < 0)
        {
                warn("cannot open `trek.dump'");
                return;

Reply via email to