mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-17 01:11:45 +00:00
Move QFS_CreatePath() to Sys_CreatePath().
This commit is contained in:
parent
4f620655be
commit
e9bd9a4baa
6 changed files with 36 additions and 25 deletions
|
@ -239,7 +239,6 @@ byte *QFS_LoadHunkFile (const char *path);
|
|||
*/
|
||||
void QFS_LoadCacheFile (const char *path, struct cache_user_s *cu);
|
||||
|
||||
int QFS_CreatePath (const char *path);
|
||||
/** Rename a file.
|
||||
|
||||
\param old_path The file to rename.
|
||||
|
|
|
@ -112,6 +112,17 @@ void Sys_DebugLog(const char *file, const char *fmt, ...) __attribute__((format(
|
|||
Sys_Error ("%s: Failed to allocate memory.", __FUNCTION__); \
|
||||
} while (0)
|
||||
|
||||
/** Create all parent directories leading to the file specified by path.
|
||||
|
||||
\param path The path to create.
|
||||
\return 0 on success, -1 on failure.
|
||||
|
||||
\note No directory will be created for the name after the final
|
||||
<code>/</code>. This is to allow the same path string to be used for
|
||||
both this function and Qopen.
|
||||
*/
|
||||
int Sys_CreatePath (const char *path);
|
||||
|
||||
//@}
|
||||
|
||||
#endif // __sys_h
|
||||
|
|
|
@ -48,7 +48,8 @@ static __attribute__ ((used)) const char rcsid[] =
|
|||
|
||||
#include "QF/pakfile.h"
|
||||
#include "QF/qendian.h"
|
||||
#include "QF/quakefs.h"
|
||||
#include "QF/quakeio.h"
|
||||
#include "QF/sys.h"
|
||||
|
||||
static const char *
|
||||
pack_get_key (void *p, void *unused)
|
||||
|
@ -260,7 +261,7 @@ pack_extract (pack_t *pack, dpackfile_t *pf)
|
|||
QFile *file;
|
||||
char buffer[16384];
|
||||
|
||||
if (QFS_CreatePath (name) == -1)
|
||||
if (Sys_CreatePath (name) == -1)
|
||||
return -1;
|
||||
if (!(file = Qopen (name, "wb")))
|
||||
return -1;
|
||||
|
|
|
@ -721,24 +721,6 @@ QFS_WriteFile (const char *filename, const void *data, int len)
|
|||
Qclose (f);
|
||||
}
|
||||
|
||||
VISIBLE int
|
||||
QFS_CreatePath (const char *path)
|
||||
{
|
||||
char *ofs;
|
||||
char *e_path = alloca (strlen (path) + 1);
|
||||
|
||||
strcpy (e_path, path);
|
||||
for (ofs = e_path + 1; *ofs; ofs++) {
|
||||
if (*ofs == '/') { // create the directory
|
||||
*ofs = 0;
|
||||
if (Sys_mkdir (e_path) == -1)
|
||||
return -1;
|
||||
*ofs = '/';
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static QFile *
|
||||
qfs_openread (const char *path, int offs, int len, int zip)
|
||||
{
|
||||
|
@ -1466,7 +1448,7 @@ QFS_Open (const char *path, const char *mode)
|
|||
if (*m == 'w' || *m == '+' || *m == 'a')
|
||||
write = 1;
|
||||
if (write)
|
||||
if (QFS_CreatePath (full_path->str) == -1)
|
||||
if (Sys_CreatePath (full_path->str) == -1)
|
||||
goto done;
|
||||
file = Qopen (full_path->str, mode);
|
||||
}
|
||||
|
@ -1496,7 +1478,7 @@ QFS_Rename (const char *old_path, const char *new_path)
|
|||
|
||||
if ((ret = qfs_expand_userpath (full_old, old_path)) != -1)
|
||||
if ((ret = qfs_expand_userpath (full_new, old_path)) != -1)
|
||||
if ((ret = QFS_CreatePath (full_new->str)) != -1)
|
||||
if ((ret = Sys_CreatePath (full_new->str)) != -1)
|
||||
ret = Qrename (full_old->str, full_new->str);
|
||||
dstring_delete (full_old);
|
||||
dstring_delete (full_new);
|
||||
|
|
|
@ -757,3 +757,21 @@ Sys_Init (void)
|
|||
signal (SIGTERM, signal_handler);
|
||||
signal (SIGFPE, signal_handler);
|
||||
}
|
||||
|
||||
VISIBLE int
|
||||
Sys_CreatePath (const char *path)
|
||||
{
|
||||
char *ofs;
|
||||
char *e_path = alloca (strlen (path) + 1);
|
||||
|
||||
strcpy (e_path, path);
|
||||
for (ofs = e_path + 1; *ofs; ofs++) {
|
||||
if (*ofs == '/') { // create the directory
|
||||
*ofs = 0;
|
||||
if (Sys_mkdir (e_path) == -1)
|
||||
return -1;
|
||||
*ofs = '/';
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ static __attribute__ ((used)) const char rcsid[] =
|
|||
#include <QF/pcx.h>
|
||||
#include <QF/qtypes.h>
|
||||
#include <QF/qendian.h>
|
||||
#include <QF/quakefs.h>
|
||||
#include <QF/quakeio.h>
|
||||
#include <QF/wadfile.h>
|
||||
#include <QF/sys.h>
|
||||
#include <QF/zone.h>
|
||||
|
@ -258,7 +258,7 @@ wad_extract (wad_t *wad, lumpinfo_t *pf)
|
|||
break;
|
||||
}
|
||||
|
||||
if (QFS_CreatePath (name.str) == -1)
|
||||
if (Sys_CreatePath (name.str) == -1)
|
||||
return -1;
|
||||
if (!(file = Qopen (name.str, "wb")))
|
||||
return -1;
|
||||
|
|
Loading…
Reference in a new issue