]>
Commit | Line | Data |
---|---|---|
3c62e7eb | 1 | /* |
4e51cc76 | 2 | * Copyright (c) 2000, 2001, Corinna Vinschen <vinschen@cygnus.com> |
3 | * | |
4 | * Redistribution and use in source and binary forms, with or without | |
5 | * modification, are permitted provided that the following conditions | |
6 | * are met: | |
7 | * 1. Redistributions of source code must retain the above copyright | |
8 | * notice, this list of conditions and the following disclaimer. | |
9 | * 2. Redistributions in binary form must reproduce the above copyright | |
10 | * notice, this list of conditions and the following disclaimer in the | |
11 | * documentation and/or other materials provided with the distribution. | |
3c62e7eb | 12 | * |
4e51cc76 | 13 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
14 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
15 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
16 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
17 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
18 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
19 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
20 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
21 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
22 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
3c62e7eb | 23 | * |
24 | * Created: Sat Sep 02 12:17:00 2000 cv | |
25 | * | |
26 | * This file contains functions for forcing opened file descriptors to | |
27 | * binary mode on Windows systems. | |
28 | */ | |
29 | ||
0b202697 | 30 | #include "includes.h" |
31 | ||
3c62e7eb | 32 | #ifdef HAVE_CYGWIN |
2f125ca1 | 33 | |
dd41ba6f | 34 | #if defined(open) && open == binary_open |
35 | # undef open | |
36 | #endif | |
37 | #if defined(pipe) && open == binary_pipe | |
38 | # undef pipe | |
39 | #endif | |
40 | ||
97ea266c | 41 | #include <sys/types.h> |
97ea266c | 42 | |
43 | #include <fcntl.h> | |
44 | #include <stdlib.h> | |
45 | #include <unistd.h> | |
9cd45ea4 | 46 | #include <windows.h> |
97ea266c | 47 | |
3c502155 | 48 | #include "xmalloc.h" |
31fb6aaf | 49 | |
9901cb37 | 50 | int |
51 | binary_open(const char *filename, int flags, ...) | |
3c62e7eb | 52 | { |
58e7f038 | 53 | va_list ap; |
54 | mode_t mode; | |
55 | ||
56 | va_start(ap, flags); | |
57 | mode = va_arg(ap, mode_t); | |
58 | va_end(ap); | |
9901cb37 | 59 | return (open(filename, flags | O_BINARY, mode)); |
3c62e7eb | 60 | } |
61 | ||
9901cb37 | 62 | int |
63 | binary_pipe(int fd[2]) | |
3c62e7eb | 64 | { |
2f125ca1 | 65 | int ret = pipe(fd); |
66 | ||
67 | if (!ret) { | |
9901cb37 | 68 | setmode(fd[0], O_BINARY); |
69 | setmode(fd[1], O_BINARY); | |
2f125ca1 | 70 | } |
9901cb37 | 71 | return (ret); |
9cd45ea4 | 72 | } |
73 | ||
9901cb37 | 74 | int |
75 | check_ntsec(const char *filename) | |
9cd45ea4 | 76 | { |
d9d96f7a | 77 | return (pathconf(filename, _PC_POSIX_PERMISSIONS)); |
3c62e7eb | 78 | } |
2f125ca1 | 79 | |
3c502155 | 80 | #define NL(x) x, (sizeof (x) - 1) |
81 | #define WENV_SIZ (sizeof (wenv_arr) / sizeof (wenv_arr[0])) | |
82 | ||
83 | static struct wenv { | |
84 | const char *name; | |
85 | size_t namelen; | |
86 | } wenv_arr[] = { | |
87 | { NL("ALLUSERSPROFILE=") }, | |
88 | { NL("COMMONPROGRAMFILES=") }, | |
89 | { NL("COMPUTERNAME=") }, | |
90 | { NL("COMSPEC=") }, | |
b54ffe05 | 91 | { NL("CYGWIN=") }, |
3c502155 | 92 | { NL("NUMBER_OF_PROCESSORS=") }, |
93 | { NL("OS=") }, | |
94 | { NL("PATH=") }, | |
95 | { NL("PATHEXT=") }, | |
96 | { NL("PROCESSOR_ARCHITECTURE=") }, | |
97 | { NL("PROCESSOR_IDENTIFIER=") }, | |
98 | { NL("PROCESSOR_LEVEL=") }, | |
99 | { NL("PROCESSOR_REVISION=") }, | |
100 | { NL("PROGRAMFILES=") }, | |
101 | { NL("SYSTEMDRIVE=") }, | |
102 | { NL("SYSTEMROOT=") }, | |
103 | { NL("TMP=") }, | |
104 | { NL("TEMP=") }, | |
b54ffe05 | 105 | { NL("WINDIR=") } |
3c502155 | 106 | }; |
107 | ||
108 | char ** | |
109 | fetch_windows_environment(void) | |
110 | { | |
111 | char **e, **p; | |
06a517d4 | 112 | unsigned int i, idx = 0; |
3c502155 | 113 | |
01d35895 | 114 | p = xcalloc(WENV_SIZ + 1, sizeof(char *)); |
3c502155 | 115 | for (e = environ; *e != NULL; ++e) { |
116 | for (i = 0; i < WENV_SIZ; ++i) { | |
117 | if (!strncmp(*e, wenv_arr[i].name, wenv_arr[i].namelen)) | |
118 | p[idx++] = *e; | |
119 | } | |
120 | } | |
121 | p[idx] = NULL; | |
122 | return p; | |
123 | } | |
124 | ||
125 | void | |
126 | free_windows_environment(char **p) | |
127 | { | |
128 | xfree(p); | |
129 | } | |
130 | ||
2f125ca1 | 131 | #endif /* HAVE_CYGWIN */ |