]> andersk Git - gssapi-openssh.git/blobdiff - openssh/openbsd-compat/xmmap.c
merged OpenSSH 5.2p1 to trunk
[gssapi-openssh.git] / openssh / openbsd-compat / xmmap.c
index 8f1d2022cd4cbfb332e5b80d17f0c106cea1b0c3..e0395e33f982919f2044581542f5d654cf19a787 100644 (file)
@@ -1,4 +1,7 @@
 /*
+ * Copyright (c) 2002 Tim Rice.  All rights reserved.
+ * MAP_FAILED code by Solar Designer.
+ * 
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+/* $Id$ */
+
 #include "includes.h"
 
+#include <sys/types.h>
 #ifdef HAVE_SYS_MMAN_H
 #include <sys/mman.h>
 #endif
+#include <sys/stat.h>
+
+#ifdef HAVE_FCNTL_H
+# include <fcntl.h>
+#endif
+#include <errno.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
 
 #include "log.h"
 
-void *xmmap(size_t size)
+void *
+xmmap(size_t size)
 {
+#ifdef HAVE_MMAP
        void *address;
 
-#ifdef HAVE_MMAP
 # ifdef MAP_ANON
        address = mmap(NULL, size, PROT_WRITE|PROT_READ, MAP_ANON|MAP_SHARED,
-           -1, 0);
+           -1, (off_t)0);
 # else
        address = mmap(NULL, size, PROT_WRITE|PROT_READ, MAP_SHARED,
-           open("/dev/zero", O_RDWR), 0);
+           open("/dev/zero", O_RDWR), (off_t)0);
 # endif
 
 #define MM_SWAP_TEMPLATE "/var/run/sshd.mm.XXXXXXXX"
-       if (address == MAP_FAILED) {
+       if (address == (void *)MAP_FAILED) {
                char tmpname[sizeof(MM_SWAP_TEMPLATE)] = MM_SWAP_TEMPLATE;
                int tmpfd;
+               mode_t old_umask;
 
+               old_umask = umask(0177);
                tmpfd = mkstemp(tmpname);
+               umask(old_umask);
                if (tmpfd == -1)
                        fatal("mkstemp(\"%s\"): %s",
                            MM_SWAP_TEMPLATE, strerror(errno));
                unlink(tmpname);
-               ftruncate(tmpfd, size);
+               if (ftruncate(tmpfd, size) != 0)
+                       fatal("%s: ftruncate: %s", __func__, strerror(errno));
                address = mmap(NULL, size, PROT_WRITE|PROT_READ, MAP_SHARED,
-                   tmpfd, 0);
+                   tmpfd, (off_t)0);
                close(tmpfd);
        }
 
This page took 0.081731 seconds and 4 git commands to generate.