define POSIXC_SELECT so we don't pull in the inline select from bsdsocket, but use...
[AROS.git] / arch / arm-native / ceboot / filesystem.c
blobce7baeb7d6e235a89e644474efd08aba5f584424
1 /*
2 Copyright © 2010-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Filesystem control routines
6 Lang: english
7 */
9 #include <dirent.h>
10 #include <stdio.h>
11 #include <string.h>
12 #include <windows.h>
13 #include <sys/stat.h>
15 #include "bootstrap.h"
16 #include "filesystem.h"
18 char *namepart(char *name)
20 while (*name)
21 name++;
23 while((name[-1] != ':') && (name[-1] != '\\') && (name[-1] != '/'))
24 name--;
26 return name;
29 static char *GetAbsName(const char *filename)
31 int l1 = strlen(bootstrapdir);
32 char *absname = malloc(l1 + strlen(filename) + 1);
34 if (absname)
36 memcpy(absname, bootstrapdir, l1);
37 strcpy(&absname[l1], filename);
40 return absname;
43 FILE *file_open(const char *filename, const char *mode)
45 FILE *res;
46 char *absname;
48 if (*filename == '\\')
50 /* The path is given as absolute, just use it */
51 return fopen(filename, mode);
54 absname = GetAbsName(filename);
55 if (!absname)
56 return NULL;
58 res = fopen(absname, mode);
59 free(absname);
61 return res;
64 int SetLog(const char *filename)
66 FILE *res;
68 if (*filename != '\\')
70 char *absname = GetAbsName(filename);
72 if (!absname)
73 return GetLastError();
75 res = freopen(absname, "a", stderr);
76 free(absname);
78 else
80 /* The path is given as absolute, just use it */
81 res = freopen(filename, "a", stderr);
83 return res ? 0 : GetLastError();