annotate compat.c @ 36:cddb02f847e1

Added unix versions of functions in compat, and added getfsname, plus some GTK fixes.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Mon, 17 Sep 2001 09:15:40 +0000
parents 432c39a4ff86
children 360bc6a5f1c9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
1 /* $Id$ */
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3 #include "compat.h"
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4 #if defined(__OS2__) || defined(__WIN32__)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5 #include <share.h>
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6 #endif
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7
36
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
8 #ifdef __UNIX__
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
9 #ifdef __FreeBSD__
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
10 #include <sys/param.h>
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
11 #include <sys/ucred.h>
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
12 #include <sys/mount.h>
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
13 #else
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
14 #include <mntent.h>
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
15 #include <sys/vfs.h>
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
16 #endif
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
17 #endif
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
18
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
19 int sockread (int a, void *b, int c, int d)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
20 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
21 #if defined(__IBMC__) || (defined(__WIN32__) && !defined(__CYGWIN32__))
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
22 return recv(a,b,c,d);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
23 #else
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
24 return read(a,b,c);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
25 #endif
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
26 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
27
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
28 int sockwrite (int a, void *b, int c, int d)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
29 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
30 #if defined(__IBMC__) || (defined(__WIN32__) && !defined(__CYGWIN32__))
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
31 return send(a,b,c,d);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
32 #else
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
33 return write(a,b,c);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
34 #endif
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
35 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
36
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
37 int sockclose(int a)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
38 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
39 #ifdef __IBMC__
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
40 return soclose(a);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
41 #elif defined(__WIN32__) && !defined(__CYGWIN32__)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
42 return closesocket(a);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
43 #else
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
44 return close(a);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
45 #endif
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
46 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
47
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
48 int makedir(char *path)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
49 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
50 #if defined(__IBMC__) || (defined(__WIN32__) && !defined(__CYGWIN32__))
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
51 return mkdir(path);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
52 #else
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
53 return mkdir(path,S_IRWXU);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
54 #endif
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
55 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
56
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
57 void nonblock(int fd)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
58 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
59 #ifdef __IBMC__
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
60 static int _nonblock = 1;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
61
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
62 ioctl(fd, FIONBIO, (char *)&_nonblock, sizeof(_nonblock));
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
63 #elif defined(__WIN32__) && !defined(__CYGWIN32__)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
64 static unsigned long _nonblock = 1;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
65
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
66 ioctlsocket(fd, FIONBIO, &_nonblock);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
67 #else
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
68 fcntl(fd, F_SETFL, O_NONBLOCK);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
69 #endif
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
70 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
71
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
72 int socksprintf(int fd, char *format, ...)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
73 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
74 va_list args;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
75 char outbuf[1024];
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
76 int len;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
77
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
78 va_start(args, format);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
79 vsprintf(outbuf, format, args);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
80 va_end(args);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
81
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
82 len = strlen(outbuf);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
83 sockwrite(fd, outbuf, len, 0);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
84
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
85 return len;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
86 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
87
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
88 void sockinit(void)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
89 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
90 #ifdef __IBMC__
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
91 sock_init();
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
92 #elif defined(__WIN32__) || defined(WINNT)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
93 WSADATA wsa;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
94
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
95 WSAStartup(MAKEWORD (1, 1), &wsa);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
96 #endif /* !WIN32 */
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
97 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
98
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
99 void sockshutdown(void)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
100 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
101 #if defined(__WIN32__) || defined(WINNT)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
102 WSACleanup();
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
103 #endif /* !WIN32 */
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
104 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
105
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
106 int sockpipe(int *pipes)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
107 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
108 #ifndef NO_DOMAIN_SOCKETS
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
109 #ifndef HAVE_PIPE
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
110 struct sockaddr_un un;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
111 #endif
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
112 #else
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
113 struct sockaddr_in server_addr;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
114 struct sockaddr_in listen_addr = { 0 };
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
115 int len = sizeof(struct sockaddr_in);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
116 struct hostent *he;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
117 #endif
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
118 #ifndef HAVE_PIPE
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
119 int tmpsock;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
120 #endif
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
121
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
122 #ifdef HAVE_PIPE
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
123 return pipe(pipes);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
124 #elif !defined(NO_DOMAIN_SOCKETS)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
125 static int instance = -1;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
126
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
127 instance++;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
128
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
129 /* Use UNIX domain sockets to pass messages */
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
130 tmpsock = socket(AF_UNIX, SOCK_STREAM, 0);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
131 pipes[1] = socket(AF_UNIX, SOCK_STREAM, 0);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
132 memset(&un, 0, sizeof(un));
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
133 un.sun_family=AF_UNIX;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
134 sprintf(un.sun_path, PIPENAME, instance);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
135 bind(tmpsock, (struct sockaddr *)&un, sizeof(un));
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
136 listen(tmpsock, 0);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
137 connect(pipes[1], (struct sockaddr *)&un, sizeof(un));
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
138 pipes[0] = accept(tmpsock, 0, 0);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
139 sockclose(tmpsock);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
140 #else
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
141 /* Use localhost socket to pass messages if no domain sockets */
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
142 he = gethostbyname("localhost");
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
143
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
144 if(he)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
145 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
146 memset(&server_addr, 0, sizeof(server_addr));
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
147 server_addr.sin_family = AF_INET;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
148 server_addr.sin_port = 0;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
149 server_addr.sin_addr.s_addr = INADDR_ANY;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
150 if ((tmpsock = socket(AF_INET, SOCK_STREAM, 0)) < 0 || bind(tmpsock, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0 || listen(tmpsock, 0) < 0)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
151 return -1;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
152
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
153 memset(&listen_addr, 0, sizeof(listen_addr));
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
154 getsockname(tmpsock, (struct sockaddr *)&listen_addr, &len);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
155
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
156 server_addr.sin_family = AF_INET;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
157 server_addr.sin_port = listen_addr.sin_port;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
158 server_addr.sin_addr.s_addr = *((unsigned long *)he->h_addr);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
159 if((pipes[1] = socket(AF_INET, SOCK_STREAM, 0)) < 0 || connect(pipes[1], (struct sockaddr *)&server_addr, sizeof(server_addr)))
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
160 return -1;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
161 else
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
162 pipes[0] = accept(tmpsock, 0, 0);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
163 sockclose(tmpsock);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
164 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
165 else
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
166 return -1;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
167 #endif
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
168 if(pipes[0] < 0 || pipes[1] < 0)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
169 return -1;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
170 return 0;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
171 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
172
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
173 /* Return in K to avoid big problems exceeding an
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
174 unsigned long when no 64bit integers are available */
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
175 #if defined(__IBMC__) || (defined(__WIN32__) && !defined(__CYGWIN32__))
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
176 unsigned long drivefree(int drive)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
177 #else
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
178 unsigned long long drivefree(int drive)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
179 #endif
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
180 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
181 #if defined(__EMX__) || defined(__OS2__)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
182 ULONG aulFSInfoBuf[40] = {0};
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
183 APIRET rc = NO_ERROR;
35
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
184 ULONG kbytes;
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
185
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
186 DosError(FERR_DISABLEHARDERR);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
187 rc = DosQueryFSInfo(drive,
35
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
188 FSIL_ALLOC,
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
189 (PVOID)aulFSInfoBuf,
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
190 sizeof(aulFSInfoBuf));
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
191
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
192 DosError(FERR_ENABLEHARDERR);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
193 if (rc != NO_ERROR)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
194 return 0;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
195
35
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
196 kbytes = aulFSInfoBuf[3]/1024;
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
197
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
198 return (unsigned long)(kbytes * aulFSInfoBuf[1] * aulFSInfoBuf[4]);
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
199 #elif defined(__WIN32__) || defined(WINNT)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
200 char buffer[10] = "C:\\";
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
201 DWORD spc, bps, fc, tc;
36
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
202 ULONG kbytes;
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
203
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
204 buffer[0] = drive + 'A' - 1;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
205
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
206 if(GetDiskFreeSpace(buffer, &spc, &bps, &fc, &tc) == 0)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
207 return 0;
36
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
208
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
209 kbytes = fc/1024;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
210
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
211 return (unsigned long)(spc*bps*kbytes);
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
212 #elif defined(__FreeBSD__)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
213 struct statfs *fsp;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
214 int entries, index = 1;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
215
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
216 entries = getmntinfo (&fsp, MNT_NOWAIT);
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
217
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
218 for (; entries-- > 0; fsp++)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
219 {
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
220 if(index == drive)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
221 return (fsp->f_bsize * fsp->f_bavail) / 1024;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
222 }
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
223 return 0;
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
224 #else
36
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
225 FILE *fp = setmntent(MOUNTED, "r");
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
226 struct mntent *mnt;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
227 struct statfs sfs;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
228 int index = 1;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
229
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
230 if(fp)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
231 {
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
232 while((mnt = getmntent(fp)))
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
233 {
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
234 if(index == drive)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
235 {
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
236 long long size = 0;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
237
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
238 if(mnt->mnt_dir)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
239 {
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
240 statfs(mnt->mnt_dir, &sfs);
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
241 size = sfs.f_bsize * (sfs.f_bavail / 1024);
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
242 }
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
243 endmntent(fp);
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
244 return size;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
245 }
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
246 index++;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
247 }
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
248 endmntent(fp);
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
249 }
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
250 return 0;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
251 #endif
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
252 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
253
35
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
254 /* Return in K to avoid big problems exceeding an
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
255 unsigned long when no 64bit integers are available */
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
256 #if defined(__IBMC__) || (defined(__WIN32__) && !defined(__CYGWIN32__))
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
257 unsigned long drivesize(int drive)
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
258 #else
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
259 unsigned long long drivesize(int drive)
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
260 #endif
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
261 {
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
262 #if defined(__EMX__) || defined(__OS2__)
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
263 ULONG aulFSInfoBuf[40] = {0};
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
264 APIRET rc = NO_ERROR;
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
265 ULONG kbytes;
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
266
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
267 DosError(FERR_DISABLEHARDERR);
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
268 rc = DosQueryFSInfo(drive,
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
269 FSIL_ALLOC,
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
270 (PVOID)aulFSInfoBuf,
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
271 sizeof(aulFSInfoBuf));
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
272
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
273 DosError(FERR_ENABLEHARDERR);
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
274 if (rc != NO_ERROR)
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
275 return 0;
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
276
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
277 kbytes = aulFSInfoBuf[2]/1024;
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
278
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
279 return (unsigned long)(kbytes * aulFSInfoBuf[1] * aulFSInfoBuf[4]);
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
280 #elif defined(__WIN32__) || defined(WINNT)
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
281 char buffer[10] = "C:\\";
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
282 DWORD spc, bps, fc, tc;
36
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
283 ULONG kbytes;
35
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
284
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
285 buffer[0] = drive + 'A' - 1;
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
286
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
287 if(GetDiskFreeSpace(buffer, &spc, &bps, &fc, &tc) == 0)
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
288 return 0;
36
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
289
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
290 kbytes = tc/1024;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
291
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
292 return (unsigned long)(spc*bps*kbytes);
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
293 #elif defined(__FreeBSD__)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
294 struct statfs *fsp;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
295 int entries, index = 1;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
296
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
297 entries = getmntinfo (&fsp, MNT_NOWAIT);
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
298
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
299 for (; entries-- > 0; fsp++)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
300 {
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
301 if(index == drive)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
302 return (fsp->f_bsize * fsp->f_blocks) / 1024;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
303 }
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
304 return 0;
35
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
305 #else
36
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
306 FILE *fp = setmntent(MOUNTED, "r");
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
307 struct mntent *mnt;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
308 struct statfs sfs;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
309 int index = 1;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
310
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
311 if(fp)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
312 {
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
313 while((mnt = getmntent(fp)))
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
314 {
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
315 if(index == drive)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
316 {
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
317 long long size = 0;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
318
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
319 if(mnt->mnt_dir)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
320 {
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
321 statfs(mnt->mnt_dir, &sfs);
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
322 size = sfs.f_bsize * (sfs.f_blocks / 1024);
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
323 }
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
324 endmntent(fp);
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
325 return size;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
326 }
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
327 index++;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
328 }
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
329 endmntent(fp);
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
330 }
35
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
331 return 0;
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
332 #endif
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
333 }
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
334
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
335 int isdrive(int drive)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
336 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
337 #if defined(__EMX__) || defined(__OS2__)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
338 APIRET rc = NO_ERROR;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
339 FSINFO volinfo;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
340
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
341 DosError(FERR_DISABLEHARDERR);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
342 rc = DosQueryFSInfo(drive,
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
343 FSIL_VOLSER,
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
344 (PVOID)&volinfo,
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
345 sizeof(FSINFO));
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
346
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
347 DosError(FERR_ENABLEHARDERR);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
348 if (rc == NO_ERROR)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
349 return 1;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
350
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
351 #elif defined(__WIN32__) || defined(WINNT)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
352 char buffer[10] = "C:\\", volname[100];
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
353 DWORD spc, bps, fc;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
354
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
355 buffer[0] = drive + 'A' - 1;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
356
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
357 if(GetVolumeInformation(buffer, volname, 100, &spc, &bps, &fc, NULL, 0) != 0)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
358 return 1;
36
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
359 #elif defined(__FreeBSD__)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
360 struct statfs *fsp;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
361 int entries, index = 1;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
362
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
363 entries = getmntinfo (&fsp, MNT_NOWAIT);
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
364
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
365 for (; entries-- > 0; fsp++)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
366 {
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
367 if(index == drive && fsp->f_blocks)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
368 return 1;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
369 }
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
370 return 0;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
371 #else
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
372 FILE *fp = setmntent(MOUNTED, "r");
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
373 struct mntent *mnt;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
374 struct statfs sfs;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
375 int index = 1;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
376
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
377 if(fp)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
378 {
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
379 while((mnt = getmntent(fp)))
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
380 {
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
381 if(index == drive)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
382 {
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
383 endmntent(fp);
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
384 if(mnt->mnt_dir)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
385 {
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
386 statfs(mnt->mnt_dir, &sfs);
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
387 if(sfs.f_blocks)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
388 return 1;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
389 }
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
390 return 0;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
391 }
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
392 index++;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
393 }
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
394 endmntent(fp);
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
395 }
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
396 #endif
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
397 return 0;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
398 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
399
36
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
400 void getfsname(int drive, char *buf, int len)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
401 {
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
402 #ifdef __UNIX__
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
403 #ifdef __FreeBSD__
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
404 struct statfs *fsp;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
405 int entries, index = 1;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
406
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
407 strncpy(buf, "Unknown", len);
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
408
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
409 entries = getmntinfo (&fsp, MNT_NOWAIT);
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
410
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
411 for (; entries-- > 0; fsp++)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
412 {
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
413 if(index == drive)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
414 strncpy(buf, fsp->f_mntonname, len);
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
415 }
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
416 #else
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
417 FILE *fp = setmntent(MOUNTED, "r");
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
418 struct mntent *mnt;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
419 int index = 1;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
420
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
421 strncpy(buf, "Unknown", len);
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
422
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
423 if(fp)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
424 {
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
425 while((mnt = getmntent(fp)))
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
426 {
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
427 if(index == drive && mnt->mnt_dir)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
428 strncpy(buf, mnt->mnt_dir, len);
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
429 index++;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
430 }
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
431 endmntent(fp);
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
432 }
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
433 #endif
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
434 #elif defined(__OS2__)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
435 /* No snprintf() on OS/2 ??? */
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
436 sprintf(buf, "Drive %c", (char)drive + 'A' - 1);
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
437 #else
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
438 snprintf(buf, len, "Drive %c", (char)drive + 'A' - 1);
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
439 #endif
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
440 }
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
441
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
442 void setfileinfo(char *filename, char *url)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
443 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
444 time_t ltime;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
445 struct tm *tm;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
446 char buffer[200], timebuf[200];
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
447 #ifdef __OS2__
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
448 const unsigned fea2listsize = 6000;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
449 char *pData;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
450 EAOP2 eaop2;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
451 PFEA2 pFEA2;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
452 #else
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
453 FILE *urlfile;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
454 #endif
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
455
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
456 ltime = time(NULL);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
457
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
458 tm = localtime(&ltime);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
459
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
460 strftime(timebuf, 200, "%c", tm);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
461
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
462 sprintf(buffer, "%s %s", url, timebuf);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
463
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
464 #ifdef __OS2__
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
465 eaop2.fpGEA2List = 0;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
466 eaop2.fpFEA2List = (PFEA2LIST)malloc(fea2listsize);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
467 pFEA2 = &eaop2.fpFEA2List->list[0];
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
468
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
469 pFEA2->fEA = 0;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
470 /* .COMMENTS is 9 characters long */
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
471 pFEA2->cbName = 9;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
472
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
473 /* space for the type and length field. */
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
474 pFEA2->cbValue = strlen(buffer)+2*sizeof(USHORT);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
475
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
476 strcpy(pFEA2->szName, ".COMMENTS");
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
477 pData = pFEA2->szName+pFEA2->cbName+1;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
478 /* data begins at first byte after the name */
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
479
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
480 *(USHORT*)pData = EAT_ASCII; /* type */
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
481 *((USHORT*)pData+1) = strlen(buffer); /* length */
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
482 strcpy(pData+2*sizeof(USHORT), buffer);/* content */
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
483
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
484 pFEA2->oNextEntryOffset = 0;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
485
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
486 eaop2.fpFEA2List->cbList = ((PCHAR)pData+2*sizeof(USHORT)+
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
487 pFEA2->cbValue)-((PCHAR)eaop2.fpFEA2List);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
488
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
489 DosSetPathInfo(filename,
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
490 FIL_QUERYEASIZE,
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
491 &eaop2,
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
492 sizeof(eaop2),
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
493 0);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
494
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
495 free((void *)eaop2.fpFEA2List);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
496 #else
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
497
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
498 if((urlfile = fopen("handyftp.url", "a"))!=NULL)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
499 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
500 fprintf(urlfile, "%s\n", buffer);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
501 fclose(urlfile);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
502 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
503 #endif
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
504 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
505
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
506 #if defined(__OS2__) || defined(__WIN32__)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
507 typedef struct _fsinfo {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
508 FILE *fp;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
509 int fd;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
510 } FSInfo;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
511
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
512 FSInfo *FSIRoot = NULL;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
513
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
514 #define FSI_MAX 100
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
515 #endif
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
516
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
517 /* Sharable fopen() and fclose() calls. */
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
518 FILE *fsopen(char *path, char *modes)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
519 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
520 #if defined(__OS2__) || defined(__WIN32__)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
521 int z;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
522
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
523 if(!FSIRoot)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
524 FSIRoot = calloc(sizeof(struct _fsinfo), FSI_MAX);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
525
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
526 for(z=0;z<FSI_MAX;z++)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
527 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
528 if(FSIRoot[z].fd < 1)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
529 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
530 int s, sopenmode = 0, wrmode = 0;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
531
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
532 /* Check the flags passed */
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
533 for(s=0;s<3;s++)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
534 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
535 if(modes[s] == 'b')
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
536 sopenmode |= O_BINARY;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
537 if(modes[s] == 'r')
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
538 wrmode |= O_RDONLY;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
539 if(modes[s] == 'w')
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
540 wrmode |= O_WRONLY;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
541 if(modes[s] == 'a')
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
542 sopenmode |= O_APPEND;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
543 if(modes[s] == 't')
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
544 sopenmode |= O_TEXT;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
545 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
546
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
547 /* Check the read/write request */
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
548 if((wrmode & O_RDONLY) && (wrmode & O_WRONLY))
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
549 sopenmode |= O_RDWR;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
550 else
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
551 sopenmode |= wrmode;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
552 FSIRoot[z].fd = _sopen(path, sopenmode, SH_DENYNO, S_IREAD|S_IWRITE);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
553 if(FSIRoot[z].fd > 0)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
554 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
555 FSIRoot[z].fp = fdopen(FSIRoot[z].fd, modes);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
556
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
557 return FSIRoot[z].fp;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
558 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
559 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
560 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
561 return NULL;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
562 #else
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
563 return fopen(path, modes);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
564 #endif
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
565 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
566
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
567 int fsclose(FILE *fp)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
568 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
569 #if defined(__OS2__) || defined(__WIN32__)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
570 if(FSIRoot)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
571 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
572
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
573 int z;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
574 for(z=0;z<FSI_MAX;z++)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
575 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
576 if(fp == FSIRoot[z].fp)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
577 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
578 int ret = fclose(fp);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
579 close(FSIRoot[z].fd);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
580 FSIRoot[z].fd = 0;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
581 FSIRoot[z].fp = NULL;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
582 return ret;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
583 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
584 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
585 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
586 #endif
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
587 return fclose(fp);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
588 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
589
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
590 char *fsgets(char *str, int size, FILE *stream)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
591 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
592 return fgets(str, size, stream);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
593 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
594
22
6a246b3bb14f Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 3
diff changeset
595 int fsseek(FILE *stream, long offset, int whence)
6a246b3bb14f Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 3
diff changeset
596 {
6a246b3bb14f Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 3
diff changeset
597 return fseek(stream, offset, whence);
6a246b3bb14f Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 3
diff changeset
598 }