1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
--- jfsw_src_20051009/source/jaudiolib/unixglob.c.orig 1970-01-01 01:00:00.000000000 +0100
+++ jfsw_src_20051009/source/jaudiolib/unixglob.c 2005-10-10 15:02:08.000000000 +0200
@@ -0,0 +1,152 @@
+/*
+Copyright (C) 2003-2004 Ryan C. Gordon. and James Bentler
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+Originally written by Ryan C. Gordon. (icculus@clutteredmind.org)
+Adapted to work with JonoF's port by James Bentler (bentler@cs.umn.edu)
+
+*/
+
+static char ApogeePath[256] = "/tmp/";
+
+#define PATH_SEP_CHAR '/'
+#define PATH_SEP_STR "/"
+#define ROOTDIR "/"
+#define CURDIR "./"
+
+#include "types.h"
+#include "compat.h"
+#include <dirent.h>
+#include <errno.h>
+
+#define Error printf
+
+#ifndef MAX_PATH
+#define MAX_PATH 256
+#endif
+
+void FixFilePath(char *filename)
+{
+ char *ptr;
+ char *lastsep = filename;
+
+ if ((!filename) || (*filename == '\0'))
+ return;
+
+ if (access(filename, F_OK) == 0) /* File exists; we're good to go. */
+ return;
+
+ for (ptr = filename; 1; ptr++)
+ {
+ if (*ptr == '\\')
+ *ptr = PATH_SEP_CHAR;
+
+ if ((*ptr == PATH_SEP_CHAR) || (*ptr == '\0'))
+ {
+ char pch = *ptr;
+ struct dirent *dent = NULL;
+ DIR *dir;
+
+ if ((pch == PATH_SEP_CHAR) && (*(ptr + 1) == '\0'))
+ return; /* eos is pathsep; we're done. */
+
+ if (lastsep == ptr)
+ continue; /* absolute path; skip to next one. */
+
+ *ptr = '\0';
+ if (lastsep == filename) {
+ dir = opendir((*lastsep == PATH_SEP_CHAR) ? ROOTDIR : CURDIR);
+
+ if (*lastsep == PATH_SEP_CHAR) {
+ lastsep++;
+ }
+ }
+ else
+ {
+ *lastsep = '\0';
+ dir = opendir(filename);
+ *lastsep = PATH_SEP_CHAR;
+ lastsep++;
+ }
+
+ if (dir == NULL)
+ {
+ *ptr = PATH_SEP_CHAR;
+ return; /* maybe dir doesn't exist? give up. */
+ }
+
+ while ((dent = readdir(dir)) != NULL)
+ {
+ if (strcasecmp(dent->d_name, lastsep) == 0)
+ {
+ /* found match; replace it. */
+ strcpy(lastsep, dent->d_name);
+ break;
+ }
+ }
+
+ closedir(dir);
+ *ptr = pch;
+ lastsep = ptr;
+
+ if (dent == NULL)
+ return; /* no match. oh well. */
+
+ if (pch == '\0') /* eos? */
+ return;
+ }
+ }
+}
+
+int32 SafeOpenWrite (const char *_filename, int32 filetype)
+{
+ int handle;
+ char filename[MAX_PATH];
+ strncpy(filename, _filename, sizeof (filename));
+ filename[sizeof (filename) - 1] = '\0';
+ FixFilePath(filename);
+
+ handle = open(filename,O_RDWR | O_BINARY | O_CREAT | O_TRUNC
+ , S_IREAD | S_IWRITE);
+
+ if (handle == -1)
+ Error ("Error opening %s: %s",filename,strerror(errno));
+
+ return handle;
+}
+
+
+void SafeWrite (int32 handle, void *buffer, int32 count)
+{
+ unsigned iocount;
+
+ while (count)
+ {
+ iocount = count > 0x8000 ? 0x8000 : count;
+ if (write (handle,buffer,iocount) != (int)iocount)
+ Error ("File write failure writing %ld bytes",count);
+ buffer = (void *)( (byte *)buffer + iocount );
+ count -= iocount;
+ }
+}
+
+
+
+void GetUnixPathFromEnvironment( char *fullname, int32 length, const char *filename )
+{
+ snprintf(fullname, length-1, "%s%s", ApogeePath, filename);
+}
|