Simplify tempfile handling. - sam - An updated version of the sam text editor.
 (HTM) git clone git://vernunftzentrum.de/sam.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
 (DIR) commit 4c9e3607fb166772364e2c55a56db63ea761d345
 (DIR) parent f1040f7de2a4570da1602e1cc13d4616b5b12405
 (HTM) Author: Rob King <jking@deadpixi.com>
       Date:   Thu,  1 Sep 2016 09:42:41 -0500
       
       Simplify tempfile handling.
       
       Diffstat:
         include/u.h                         |       2 +-
         sam/disc.c                          |       2 +-
         sam/sam.h                           |       2 +-
         sam/unix.c                          |      28 +++++-----------------------
       
       4 files changed, 8 insertions(+), 26 deletions(-)
       ---
 (DIR) diff --git a/include/u.h b/include/u.h
       @@ -10,7 +10,7 @@
        
        typedef uint16_t ushort;
        typedef uint8_t  uchar;
       -typedef wchar_t  Rune;
       +typedef uint16_t  Rune;
        
        #if USE64BITS == 0
        typedef uint32_t ulong;
 (DIR) diff --git a/sam/disc.c b/sam/disc.c
       @@ -20,7 +20,7 @@ Dstart(void)
                for(i=0, dd=desc; dd->fd; i++, dd++)
                        if(i == NBUFFILES-1)
                                panic("too many buffer files");
       -        fd = newtmp(i);
       +        fd = newtmp();
                if(fd < 0)
                        panic("can't create buffer file");
                dd->fd = fd;
 (DIR) diff --git a/sam/sam.h b/sam/sam.h
       @@ -281,7 +281,7 @@ void        move(File*, Address);
        void        moveto(File*, Range);
        File        *newfile(void);
        void        nextmatch(File*, String*, Posn, int);
       -int        newtmp(int);
       +int        newtmp(void);
        void        notifyf(void*, char*);
        void        panic(char*);
        void        printposn(File*, int);
 (DIR) diff --git a/sam/unix.c b/sam/unix.c
       @@ -120,31 +120,13 @@ notifyf(void *a, char *b)        /* never called */
        {
        }
        
       -/*
       - *        if your system doesn't have tempnam(), substitute the following
       - *        code for this function:
       - *        FILE *f;
       - *        f = tmpfile();
       - *        if (f == 0)
       - *                return -1;
       - *        return fileno(f);
       - *
       - *        we use tempnam to allow temp files to be allocated in the
       - *        most efficient place; nodes with disks may mount /usr/tmp
       - *        remotely, causing excessive network traffic.  place
       - *        the temp files locally, if possible.
       - */
        int
       -newtmp(int i)
       +newtmp(void)
        {
       -        char s[1024] = {0};
       -        sprint(s, "%s/sam.XXXXXX", TMPDIR);
       -        int fd = mkstemp(s);
       -        if (fd >= 0)
       -        {
       -                unlink(s);
       -        }
       -        return fd;
       +    FILE *f = tmpfile();
       +    if (f)
       +        return fileno(f);
       +    panic("could not create tempfile!");
        }
        
        void