workbench/classes/zune: WIP - Unsorted -Wall fixes
[AROS.git] / workbench / classes / zune / prefseditor / support.c
blob06ea95015ce7c389d66b8b3a7d93e9c60f036c31
1 /*
2 Copyright © 2004, The AROS Development Team. All rights reserved.
3 This file is part of the PrefsEditor class, which is distributed under
4 the terms of version 2.1 of the GNU Lesser General Public License.
6 $Id$
7 */
9 #include <exec/types.h>
10 #include <proto/dos.h>
11 #include <proto/utility.h>
12 #include <proto/exec.h>
14 #include <stdio.h>
15 #include <aros/debug.h>
17 #include "support.h"
19 /* Note: buffer *MUST* be large enough for atleast strlen(prefix) + 8 + 1 */
20 BPTR CreateTemporary(STRPTR buffer, CONST_STRPTR prefix)
22 BPTR fh;
24 while (TRUE)
26 sprintf(buffer, "%s%08lx", prefix, GetUniqueID());
27 fh = Open(buffer, MODE_NEWFILE);
29 if (fh != BNULL)
31 return fh;
33 else if (IoErr() != ERROR_OBJECT_EXISTS)
35 return BNULL;
40 BOOL MakeDir(CONST_STRPTR path)
42 BPTR lock = CreateDir(path);
44 if (lock != BNULL)
46 UnLock(lock);
47 return TRUE;
50 return FALSE;
53 BOOL MakeDirs(STRPTR path)
55 STRPTR position;
56 BOOL success = FALSE;
57 BPTR lock = BNULL;
59 for (position = path; *position != '\0'; position++)
61 if (*position == '/')
63 *position = '\0';
65 if ((lock = Lock(path, SHARED_LOCK)) != BNULL)
67 UnLock(lock);
68 success = TRUE;
70 else
72 success = MakeDir(path);
75 *position = '/';
77 if (!success) return FALSE;
81 return TRUE;