Release 960114
[wine/multimedia.git] / misc / dos_fs.c
blobb01f6b0177046c821e46501bee7f54ff74095894
1 /*
2 * DOS-FS
3 * NOV 1993 Erik Bos <erik@xs4all.nl>
5 * FindFile by Bob, hacked for dos & unixpaths by Erik.
7 * Bugfix by dash@ifi.uio.no: ToUnix() was called to often
8 */
10 #include <ctype.h>
11 #include <errno.h>
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include <sys/stat.h>
16 #include <pwd.h>
17 #include <dirent.h>
18 #include <unistd.h>
19 #include <fcntl.h>
21 #if defined(__linux__) || defined(sun)
22 #include <sys/vfs.h>
23 #endif
24 #if defined(__NetBSD__) || defined(__FreeBSD__)
25 #include <sys/param.h>
26 #include <sys/mount.h>
27 #include <sys/errno.h>
28 #endif
29 #ifdef __svr4__
30 #include <sys/statfs.h>
31 #endif
32 #include "wine.h"
33 #include "windows.h"
34 #include "msdos.h"
35 #include "dos_fs.h"
36 #include "comm.h"
37 #include "task.h"
38 #include "stddebug.h"
39 #include "debug.h"
40 #include "xmalloc.h"
42 #define WINE_INI_USER "~/.winerc"
45 static void ExpandTildeString(char *s)
47 struct passwd *entry;
48 char temp[1024], *ptr = temp;
50 strcpy(temp, s);
52 while (*ptr)
54 if (*ptr != '~')
56 *s++ = *ptr++;
57 continue;
60 ptr++;
62 if ( (entry = getpwuid(getuid())) == NULL)
64 continue;
67 strcpy(s, entry->pw_dir);
68 s += strlen(entry->pw_dir);
70 *s = 0;
75 int DOS_GetFreeSpace(int drive, long *size, long *available)
77 struct statfs info;
78 const char *root;
80 if (!DRIVE_IsValid(drive)) return 0;
81 root = DRIVE_GetRoot(drive);
83 #ifdef __svr4__
84 if (statfs( root, &info, 0, 0) < 0) {
85 #else
86 if (statfs( root, &info) < 0) {
87 #endif
88 fprintf(stderr,"dosfs: cannot do statfs(%s)\n", root );
89 return 0;
92 *size = info.f_bsize * info.f_blocks;
93 #ifdef __svr4__
94 *available = info.f_bfree * info.f_bsize;
95 #else
96 *available = info.f_bavail * info.f_bsize;
97 #endif
98 return 1;
101 /**********************************************************************
102 * WineIniFileName
104 char *WineIniFileName(void)
106 int fd;
107 static char *filename = NULL;
108 static char name[256];
110 if (filename)
111 return filename;
113 strcpy(name, WINE_INI_USER);
114 ExpandTildeString(name);
115 if ((fd = open(name, O_RDONLY)) != -1) {
116 close(fd);
117 filename = name;
118 return filename;
120 if ((fd = open(WINE_INI_GLOBAL, O_RDONLY)) != -1) {
121 close(fd);
122 filename = WINE_INI_GLOBAL;
123 return filename;
125 fprintf(stderr,"wine: can't open configuration file %s or %s !\n",
126 WINE_INI_GLOBAL, WINE_INI_USER);
127 exit(1);