aboutsummaryrefslogtreecommitdiff
path: root/shared/common/fi.c
diff options
context:
space:
mode:
authorN.N. <krzyszcz@users.sourceforge.net>2004-12-08 15:45:27 +0000
committerN.N. <krzyszcz@users.sourceforge.net>2004-12-08 15:45:27 +0000
commit155fa2c04c7e415803e1546dcde0a47442eef4b3 (patch)
tree94a1714fee23703bddef850e7b5acb60a9c39631 /shared/common/fi.c
parentd5a39ff6469f8762218c00a34f4b0a120a56332b (diff)
*** empty log message ***
svn path=/trunk/externals/miXed/; revision=2361
Diffstat (limited to 'shared/common/fi.c')
-rw-r--r--shared/common/fi.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/shared/common/fi.c b/shared/common/fi.c
new file mode 100644
index 0000000..e46d001
--- /dev/null
+++ b/shared/common/fi.c
@@ -0,0 +1,54 @@
+/* Copyright (c) 2004 krzYszcz and others.
+ * For information on usage and redistribution, and for a DISCLAIMER OF ALL
+ * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
+
+#ifdef NT
+#include <io.h>
+#else
+#include <unistd.h>
+#endif
+#include <stdio.h>
+#include <string.h>
+#include "m_pd.h"
+#include "fi.h"
+
+FILE *firead_open(char *filename, t_canvas *cv, int textmode)
+{
+ int fd;
+ char path[MAXPDSTRING+2], *nameptr;
+ t_symbol *dirsym = (cv ? canvas_getdir(cv) : 0);
+ /* path arg is returned unbashed (system-independent) */
+ if ((fd = open_via_path((dirsym ? dirsym->s_name : ""), filename,
+ "", path, &nameptr, MAXPDSTRING, 1)) < 0)
+ return (0);
+ /* Closing/reopening dance. This is unnecessary under linux, and we
+ could have tried to convert fd to fp, but under windows open_via_path()
+ returns what seems to be an invalid fd.
+ LATER try to understand what is going on here... */
+ close(fd);
+ if (path != nameptr)
+ {
+ char *slashpos = path + strlen(path);
+ *slashpos++ = '/';
+ /* try not to be dependent on current open_via_path() implementation */
+ if (nameptr != slashpos)
+ strcpy(slashpos, nameptr);
+ }
+ sys_bashfilename(path, path);
+ return (fopen(path, (textmode ? "r" : "rb")));
+}
+
+FILE *fiwrite_open(char *filename, t_canvas *cv, int textmode)
+{
+ char path[MAXPDSTRING+2];
+ if (cv)
+ /* path arg is returned unbashed (system-independent) */
+ canvas_makefilename(cv, filename, path, MAXPDSTRING);
+ else
+ {
+ strncpy(path, filename, MAXPDSTRING);
+ path[MAXPDSTRING-1] = 0;
+ }
+ sys_bashfilename(path, path);
+ return (fopen(path, (textmode ? "w" : "wb")));
+}