[SCM] Samba Shared Repository - branch v4-0-test updated - release-4-0-0alpha3-302-ga9604fe

Stefan Metzmacher metze at samba.org
Wed May 7 11:56:41 GMT 2008


The branch, v4-0-test has been updated
       via  a9604fe4a323dccb537cf02ea7594437b4995803 (commit)
      from  6a1b7f56afa7475880f4eb5f0b669fd2b95a1d8f (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v4-0-test


- Log -----------------------------------------------------------------
commit a9604fe4a323dccb537cf02ea7594437b4995803
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed May 7 13:10:31 2008 +0200

    libreplace: always provide utime() and utimes()
    
    I'd like to also provide futimes(), but it seems
    that some systems doesn't support a it at kernel level.
    
    If someone knows how to write a portable replacement
    for futimes() please tell me...
    
    metze

-----------------------------------------------------------------------

Summary of changes:
 source/lib/replace/README           |    2 +
 source/lib/replace/replace.c        |   27 +++++++
 source/lib/replace/replace.h        |   10 +++
 source/lib/replace/system/config.m4 |    2 +-
 source/lib/replace/system/time.h    |   15 ++++
 source/lib/replace/test/testsuite.c |  145 +++++++++++++++++++++++++++++++++++
 6 files changed, 200 insertions(+), 1 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source/lib/replace/README b/source/lib/replace/README
index 43f7b08..4d94317 100644
--- a/source/lib/replace/README
+++ b/source/lib/replace/README
@@ -62,6 +62,8 @@ getnameinfo
 gai_strerror
 getifaddrs
 freeifaddrs
+utime
+utimes
 
 Types:
 bool
diff --git a/source/lib/replace/replace.c b/source/lib/replace/replace.c
index 443da2a..2c3f14c 100644
--- a/source/lib/replace/replace.c
+++ b/source/lib/replace/replace.c
@@ -584,3 +584,30 @@ int rep_unsetenv(const char *name)
 	return 0;
 }
 #endif
+
+#ifndef HAVE_UTIME
+int rep_utime(const char *filename, const struct utimbuf *buf)
+{
+	errno = ENOSYS;
+	return -1;
+}
+#endif
+
+#ifndef HAVE_UTIMES
+int rep_utimes(const char *filename, const struct timeval tv[2])
+{
+	struct utimbuf u;
+
+	u.actime = tv[0].tv_sec;
+	if (tv[0].tv_usec > 500000) {
+		u.actime += 1;
+	}
+
+	u.modtime = tv[1].tv_sec;
+	if (tv[1].tv_usec > 500000) {
+		u.modtime += 1;
+	}
+
+	return utime(filename, &u);
+}
+#endif
diff --git a/source/lib/replace/replace.h b/source/lib/replace/replace.h
index bf95169..c69ea6c 100644
--- a/source/lib/replace/replace.h
+++ b/source/lib/replace/replace.h
@@ -101,6 +101,16 @@ void *rep_memmove(void *dest,const void *src,int size);
 /* prototype is in "system/time.h" */
 #endif
 
+#ifndef HAVE_UTIME
+#define utime rep_utime
+/* prototype is in "system/time.h" */
+#endif
+
+#ifndef HAVE_UTIMES
+#define utimes rep_utimes
+/* prototype is in "system/time.h" */
+#endif
+
 #ifndef HAVE_STRLCPY
 #define strlcpy rep_strlcpy
 size_t rep_strlcpy(char *d, const char *s, size_t bufsize);
diff --git a/source/lib/replace/system/config.m4 b/source/lib/replace/system/config.m4
index ae26bb5..5c9b53d 100644
--- a/source/lib/replace/system/config.m4
+++ b/source/lib/replace/system/config.m4
@@ -9,7 +9,7 @@ AC_CHECK_HEADERS(sys/select.h)
 # time
 AC_CHECK_HEADERS(sys/time.h utime.h)
 AC_HEADER_TIME
-AC_CHECK_FUNCS(utime utimes futimes)
+AC_CHECK_FUNCS(utime utimes)
 
 # wait
 AC_HEADER_SYS_WAIT
diff --git a/source/lib/replace/system/time.h b/source/lib/replace/system/time.h
index 036812a..4abf295 100644
--- a/source/lib/replace/system/time.h
+++ b/source/lib/replace/system/time.h
@@ -39,6 +39,11 @@
 
 #ifdef HAVE_UTIME_H
 #include <utime.h>
+#else
+struct utimbuf {
+	time_t actime;       /* access time */
+	time_t modtime;      /* modification time */
+};
 #endif
 
 #ifndef HAVE_MKTIME
@@ -51,4 +56,14 @@ time_t rep_mktime(struct tm *t);
 time_t rep_timegm(struct tm *tm);
 #endif
 
+#ifndef HAVE_UTIME
+/* define is in "replace.h" */
+int rep_utime(const char *filename, const struct utimbuf *buf);
+#endif
+
+#ifndef HAVE_UTIMES
+/* define is in "replace.h" */
+int rep_utimes(const char *filename, const struct timeval tv[2]);
+#endif
+
 #endif
diff --git a/source/lib/replace/test/testsuite.c b/source/lib/replace/test/testsuite.c
index b538360..1e82909 100644
--- a/source/lib/replace/test/testsuite.c
+++ b/source/lib/replace/test/testsuite.c
@@ -872,6 +872,149 @@ static int test_getifaddrs(void)
 	return true;
 }
 
+static int test_utime(void)
+{
+	struct utimbuf u;
+	struct stat st1, st2, st3;
+	int fd;
+
+	printf("test: utime\n");
+	unlink(TESTFILE);
+
+	fd = open(TESTFILE, O_RDWR|O_CREAT, 0600);
+	if (fd == -1) {
+		printf("failure: utime [\n"
+		       "creating '%s' failed - %s\n]\n",
+		       TESTFILE, strerror(errno));
+		return false;
+	}
+
+	if (fstat(fd, &st1) != 0) {
+		printf("failure: utime [\n"
+		       "fstat (1) failed - %s\n]\n",
+		       strerror(errno));
+		return false;
+	}
+
+	u.actime = st1.st_atime + 300;
+	u.modtime = st1.st_mtime - 300;
+	if (utime(TESTFILE, &u) != 0) {
+		printf("failure: utime [\n"
+		       "utime(&u) failed - %s\n]\n",
+		       strerror(errno));
+		return false;
+	}
+
+	if (fstat(fd, &st2) != 0) {
+		printf("failure: utime [\n"
+		       "fstat (2) failed - %s\n]\n",
+		       strerror(errno));
+		return false;
+	}
+
+	if (utime(TESTFILE, NULL) != 0) {
+		printf("failure: utime [\n"
+		       "utime(NULL) failed - %s\n]\n",
+		       strerror(errno));
+		return false;
+	}
+
+	if (fstat(fd, &st3) != 0) {
+		printf("failure: utime [\n"
+		       "fstat (3) failed - %s\n]\n",
+		       strerror(errno));
+		return false;
+	}
+
+#define CMP_VAL(a,c,b) do { \
+	if (a c b) { \
+		printf("failure: utime [\n" \
+		       "%s: %s(%d) %s %s(%d)\n]\n", \
+		       __location__, \
+		       #a, (int)a, #c, #b, (int)b); \
+		return false; \
+	} \
+} while(0)
+#define EQUAL_VAL(a,b) CMP_VAL(a,!=,b)
+#define GREATER_VAL(a,b) CMP_VAL(a,<=,b)
+#define LESSER_VAL(a,b) CMP_VAL(a,>=,b)
+
+	EQUAL_VAL(st2.st_atime, st1.st_atime + 300);
+	EQUAL_VAL(st2.st_mtime, st1.st_mtime - 300);
+	LESSER_VAL(st3.st_atime, st2.st_atime);
+	GREATER_VAL(st3.st_mtime, st2.st_mtime);
+
+#undef CMP_VAL
+#undef EQUAL_VAL
+#undef GREATER_VAL
+#undef LESSER_VAL
+
+	unlink(TESTFILE);
+	printf("success: utime\n");
+	return true;
+}
+
+static int test_utimes(void)
+{
+	struct timeval tv[2];
+	struct stat st1, st2;
+	int fd;
+
+	printf("test: utimes\n");
+	unlink(TESTFILE);
+
+	fd = open(TESTFILE, O_RDWR|O_CREAT, 0600);
+	if (fd == -1) {
+		printf("failure: utimes [\n"
+		       "creating '%s' failed - %s\n]\n",
+		       TESTFILE, strerror(errno));
+		return false;
+	}
+
+	if (fstat(fd, &st1) != 0) {
+		printf("failure: utimes [\n"
+		       "fstat (1) failed - %s\n]\n",
+		       strerror(errno));
+		return false;
+	}
+
+	ZERO_STRUCT(tv);
+	tv[0].tv_sec = st1.st_atime + 300;
+	tv[1].tv_sec = st1.st_mtime - 300;
+	if (utimes(TESTFILE, tv) != 0) {
+		printf("failure: utimes [\n"
+		       "utimes(tv) failed - %s\n]\n",
+		       strerror(errno));
+		return false;
+	}
+
+	if (fstat(fd, &st2) != 0) {
+		printf("failure: utimes [\n"
+		       "fstat (2) failed - %s\n]\n",
+		       strerror(errno));
+		return false;
+	}
+
+#define EQUAL_VAL(a,b) do { \
+	if (a != b) { \
+		printf("failure: utimes [\n" \
+		       "%s: %s(%d) != %s(%d)\n]\n", \
+		       __location__, \
+		       #a, (int)a, #b, (int)b); \
+		return false; \
+	} \
+} while(0)
+
+	EQUAL_VAL(st2.st_atime, st1.st_atime + 300);
+	EQUAL_VAL(st2.st_mtime, st1.st_mtime - 300);
+
+#undef EQUAL_VAL
+
+	unlink(TESTFILE);
+	printf("success: utimes\n");
+	return true;
+}
+
 struct torture_context;
 bool torture_local_replace(struct torture_context *ctx)
 {
@@ -920,6 +1063,8 @@ bool torture_local_replace(struct torture_context *ctx)
 	ret &= test_socketpair();
 	ret &= test_strptime();
 	ret &= test_getifaddrs();
+	ret &= test_utime();
+	ret &= test_utimes();
 
 	return ret;
 }


-- 
Samba Shared Repository


More information about the samba-cvs mailing list