ref: 0e1d3a54adfb5fae7edcba12b46ce3756ca464b9
parent: 602ff71c76e6b4ee9af2a7dd423a6fd906a8ac11
author: qwx <>
date: Fri Jun 1 03:55:58 EDT 2018
fs: don't create existing directories
--- a/files.c
+++ b/files.c
@@ -105,7 +105,7 @@
if (*ofs == '/')
{ // create the directory
*ofs = 0;
- Sys_Mkdir (path);
+ mkdir(path);
*ofs = '/';
}
}
--- a/fns.h
+++ b/fns.h
@@ -1,3 +1,5 @@
+int mkdir(char*);
+
void Qcommon_Init(int, char **);
void Qcommon_Frame(int);
void Z_Free(void *);
@@ -52,7 +54,6 @@
char* Sys_FindNext(int);
void Sys_FindClose(void);
int Sys_Milliseconds(void);
-void Sys_Mkdir(char *);
void Sys_Init(void);
void Sys_AppActivate(void);
void Sys_UnloadGame(void);
--- /dev/null
+++ b/fs.c
@@ -1,0 +1,20 @@
+#include <u.h>
+#include <libc.h>
+#include <stdio.h>
+#include "dat.h"
+#include "fns.h"
+
+int
+mkdir(char *path)
+{
+ int fd;
+
+ if(access(path, AEXIST) == 0)
+ return 0;
+ if((fd = create(path, OREAD, DMDIR|0777)) < 0){
+ fprint(2, "mkdir: %r\n");
+ return -1;
+ }
+ close(fd);
+ return 0;
+}
--- a/mkfile
+++ b/mkfile
@@ -19,6 +19,7 @@
cl_scrn.$O\
cl_view.$O\
console.$O\
+ fs.$O\
keys.$O\
menu.$O\
snd_dma.$O\
--- a/r_misc.c
+++ b/r_misc.c
@@ -524,7 +524,7 @@
// create the scrnshots directory if it doesn't exist
Com_sprintf (checkname, sizeof(checkname), "%s/scrnshot", ri.FS_Gamedir());
- Sys_Mkdir (checkname);
+ mkdir(checkname);
//
// find a file name to save it to
--- a/sys.c
+++ b/sys.c
@@ -327,17 +327,6 @@
return curtime;
}
-void
-Sys_Mkdir(char *path)
-{
- int d;
-
- if((d = create(path, OREAD, DMDIR|0777)) < 0)
- fprint(2, "Sys_Mkdir:create: %r\n");
- else
- close(d);
-}
-
vlong
flen(int fd)
{
@@ -348,18 +337,6 @@
return -1;
}
return *((vlong *)(bs+2+2+4+1+4+8+4+4+4)); /* length[8] */
-}
-
-int
-Sys_FileTime(char *path)
-{
- uchar sb[1024];
-
- if(stat(path, sb, sizeof sb) < 0){
- fprint(2, "Sys_FileTime:stat: %r\n");
- return -1;
- }
- return *((int *)(sb+25));
}
void