Guest User

Untitled

a guest
Nov 19th, 2017
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.35 KB | None | 0 0
  1. From 355e4ad4cef84f516e0e7c521ecc047b3146e73e Mon Sep 17 00:00:00 2001
  2. From: Alexander von Gluck IV <kallisti5@unixzen.com>
  3. Date: Thu, 16 Nov 2017 08:00:48 -0600
  4. Subject: [PATCH] libbsd: Move lutimes to bsd compat
  5.  
  6. * Rework be149e8ccf9 since lutimes isn't posix
  7. ---
  8. headers/compatibility/bsd/sys/time.h | 29 +++++++++++++++++++++++++++++
  9. headers/posix/sys/time.h | 1 -
  10. src/libs/bsd/Jamfile | 1 +
  11. src/libs/bsd/lutimes.c | 23 +++++++++++++++++++++++
  12. src/system/libroot/posix/sys/utimes.c | 31 ++++++-------------------------
  13. 5 files changed, 59 insertions(+), 26 deletions(-)
  14. create mode 100644 headers/compatibility/bsd/sys/time.h
  15. create mode 100644 src/libs/bsd/lutimes.c
  16.  
  17. diff --git a/headers/compatibility/bsd/sys/time.h b/headers/compatibility/bsd/sys/time.h
  18. new file mode 100644
  19. index 0000000000..6e71a66813
  20. --- /dev/null
  21. +++ b/headers/compatibility/bsd/sys/time.h
  22. @@ -0,0 +1,29 @@
  23. +/*
  24. + * Copyright 2016-2017 Haiku, Inc. All Rights Reserved.
  25. + * Distributed under the terms of the MIT License.
  26. + */
  27. +#ifndef _BSD_SYS_TIME_H_
  28. +#define _BSD_SYS_TIME_H_
  29. +
  30. +
  31. +#include_next <sys/time.h>
  32. +
  33. +
  34. +#ifdef _BSD_SOURCE
  35. +
  36. +
  37. +#ifdef __cplusplus
  38. +extern "C" {
  39. +#endif
  40. +
  41. +int lutimes(const char *path, const struct timeval times[2]);
  42. +
  43. +#ifdef __cplusplus
  44. +}
  45. +#endif
  46. +
  47. +
  48. +#endif
  49. +
  50. +
  51. +#endif /* _BSD_SYS_TIME_H_ */
  52. diff --git a/headers/posix/sys/time.h b/headers/posix/sys/time.h
  53. index bb1277ddfe..dfa8d8cf23 100644
  54. --- a/headers/posix/sys/time.h
  55. +++ b/headers/posix/sys/time.h
  56. @@ -44,7 +44,6 @@ extern int setitimer(int which, const struct itimerval *value, struct itimerval
  57. extern int gettimeofday(struct timeval *tv, void *tz);
  58.  
  59. extern int utimes(const char *path, const struct timeval times[2]);
  60. -extern int lutimes(const char *path, const struct timeval times[2]);
  61. /* legacy */
  62.  
  63. #ifdef __cplusplus
  64. diff --git a/src/libs/bsd/Jamfile b/src/libs/bsd/Jamfile
  65. index d8e6c604a9..810ae74933 100644
  66. --- a/src/libs/bsd/Jamfile
  67. +++ b/src/libs/bsd/Jamfile
  68. @@ -16,6 +16,7 @@ for architectureObject in [ MultiArchSubDirSetup ] {
  69. fgetln.c
  70. getpass.c
  71. issetugid.c
  72. + lutimes.c
  73. progname.c
  74. pty.cpp
  75. signal.c
  76. diff --git a/src/libs/bsd/lutimes.c b/src/libs/bsd/lutimes.c
  77. new file mode 100644
  78. index 0000000000..f43bbf8a83
  79. --- /dev/null
  80. +++ b/src/libs/bsd/lutimes.c
  81. @@ -0,0 +1,23 @@
  82. +/*
  83. + * Copyright, 2016-2017 Haiku, Inc. All rights reserved.
  84. + * Released under the terms of the MIT license.
  85. + *
  86. + * Authors:
  87. + * Alexander von Gluck IV, kallisti5@unixzen.com
  88. + */
  89. +
  90. +
  91. +#include <sys/time.h>
  92. +
  93. +#include <OS.h>
  94. +
  95. +
  96. +extern int _utimes(const char* path, const struct timeval times[2],
  97. + bool traverseLink);
  98. +
  99. +
  100. +int
  101. +lutimes(const char* path, const struct timeval times[2])
  102. +{
  103. + return _utimes(path, times, false);
  104. +}
  105. diff --git a/src/system/libroot/posix/sys/utimes.c b/src/system/libroot/posix/sys/utimes.c
  106. index 09794ea3c4..b144b06351 100644
  107. --- a/src/system/libroot/posix/sys/utimes.c
  108. +++ b/src/system/libroot/posix/sys/utimes.c
  109. @@ -16,8 +16,8 @@
  110. #include <syscall_utils.h>
  111.  
  112.  
  113. -int
  114. -utimes(const char* path, const struct timeval times[2])
  115. +extern int
  116. +_utimes(const char* path, const struct timeval times[2], bool traverseLink)
  117. {
  118. struct stat stat;
  119. status_t status;
  120. @@ -35,36 +35,17 @@ utimes(const char* path, const struct timeval times[2])
  121. }
  122.  
  123. // traverseLeafLink == true
  124. - status = _kern_write_stat(-1, path, true, &stat, sizeof(struct stat),
  125. - B_STAT_MODIFICATION_TIME | B_STAT_ACCESS_TIME);
  126. + status = _kern_write_stat(-1, path, traverseLink, &stat,
  127. + sizeof(struct stat), B_STAT_MODIFICATION_TIME | B_STAT_ACCESS_TIME);
  128.  
  129. RETURN_AND_SET_ERRNO(status);
  130. }
  131.  
  132.  
  133. int
  134. -lutimes(const char* path, const struct timeval times[2])
  135. +utimes(const char* path, const struct timeval times[2])
  136. {
  137. - struct stat stat;
  138. - status_t status;
  139. -
  140. - if (times != NULL) {
  141. - stat.st_atim.tv_sec = times[0].tv_sec;
  142. - stat.st_atim.tv_nsec = times[0].tv_usec * 1000;
  143. -
  144. - stat.st_mtim.tv_sec = times[1].tv_sec;
  145. - stat.st_mtim.tv_nsec = times[1].tv_usec * 1000;
  146. - } else {
  147. - bigtime_t now = real_time_clock_usecs();
  148. - stat.st_atim.tv_sec = stat.st_mtim.tv_sec = now / 1000000;
  149. - stat.st_atim.tv_nsec = stat.st_mtim.tv_nsec = (now % 1000000) * 1000;
  150. - }
  151. -
  152. - // traverseLeafLink == false
  153. - status = _kern_write_stat(-1, path, false, &stat, sizeof(struct stat),
  154. - B_STAT_MODIFICATION_TIME | B_STAT_ACCESS_TIME);
  155. -
  156. - RETURN_AND_SET_ERRNO(status);
  157. + return _utimes(path, times, true);
  158. }
  159.  
  160.  
  161. --
  162. 2.14.3
Add Comment
Please, Sign In to add comment