Prechádzať zdrojové kódy

Added utime_() function.

Brucey 3 rokov pred
rodič
commit
f909b7ba48
2 zmenil súbory, kde vykonal 39 pridanie a 0 odobranie
  1. 1 0
      stdc.mod/stdc.bmx
  2. 38 0
      stdc.mod/stdc.c

+ 1 - 0
stdc.mod/stdc.bmx

@@ -221,6 +221,7 @@ Function closedir_:Int( dir:Byte Ptr )
 Function readdir_$( dir:Byte Ptr )
 Function stat_:Int( path$,st_mode:Int Var,st_size:Long Var,st_mtime:Int Var,st_ctime:Int Var,st_atime:Int Var )
 Function system_:Int( cmd$ )
+Function utime_:Int( path:String, ty:Int, time:Long)
 
 'misc
 Function abort_()="void abort() !"

+ 38 - 0
stdc.mod/stdc.c

@@ -17,6 +17,7 @@
 #include <winsock2.h>
 #include <windows.h>
 #include <ws2tcpip.h>
+#include <utime.h>
 
 extern int bmx_inet_pton(int af, const char *src, void *dst);
 #define inet_pton bmx_inet_pton
@@ -33,6 +34,7 @@ extern int _bbusew;
 #include <sys/socket.h>
 #include <netdb.h>
 #include <arpa/inet.h>
+#include <utime.h>
 
 #endif
 
@@ -351,6 +353,24 @@ int clock_gettime_(int id, struct timespec * spec) {
 	return 0;
 }
 
+int utime_( BBString *path, int type, BBLONG time){
+	struct _utimbuf times = {0,0};
+	
+	if ( type == 0 ) {
+		times.modtime = time;
+	} else if ( type == 2 ) {
+		times.actime = time;
+	} else {
+		return -1;
+	}
+
+	wchar_t *p = bbStringToWString(path);
+	int res = _wutime( p, &times);
+	bbMemFree(p);
+	
+	return res == 0 ? 0 : -1;
+}
+
 #else
 
 int getchar_(){
@@ -477,6 +497,24 @@ int stat_( BBString *path,int *t_mode,BBLONG *t_size,int *t_mtime,int *t_ctime,i
 	return 0;
 }
 
+int utime_( BBString *path, int type, BBLONG time){
+	struct utimbuf times = {0,0};
+
+	if ( type == 0 ) {
+		times.modtime = time;
+	} else if ( type == 2 ) {
+		times.actime = time;
+	} else {
+		return -1;
+	}
+
+	char *p = (char*)bbStringToUTF8String( path );
+	int res = utime( p, &times);
+	bbMemFree(p);
+	
+	return res == 0 ? 0 : -1;
+}
+
 int system_( BBString *cmd ){
 #if TARGET_OS_IPHONE || TARGET_OS_TV
 	bbExThrowCString("Not available on iOS");