From 215c1a6c7599094d3afec5e79d8ed0c812b6d87b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 2 Jul 2009 14:05:44 +0000 Subject: [PATCH] * _user_{get|set}_tzfilename() can now be used with NULL filename pointers in case one just want to get or set the timezone. * Minor cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31370 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/kernel/real_time_clock.c | 31 ++++++++++++++++++----------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/system/kernel/real_time_clock.c b/src/system/kernel/real_time_clock.c index 3b9967e59c..e0739122c8 100644 --- a/src/system/kernel/real_time_clock.c +++ b/src/system/kernel/real_time_clock.c @@ -297,18 +297,18 @@ _user_set_tzfilename(const char *filename, size_t length, bool isGMT) if (geteuid() != 0) return B_NOT_ALLOWED; - if (!IS_USER_ADDRESS(filename) - || filename == NULL - || user_strlcpy(sTimezoneFilename, filename, - B_PATH_NAME_LENGTH) < B_OK) - return B_BAD_ADDRESS; + if (filename != NULL && length > 0) { + if (!IS_USER_ADDRESS(filename) + || user_strlcpy(sTimezoneFilename, filename, B_PATH_NAME_LENGTH) < 0) + return B_BAD_ADDRESS; + } sIsGMT = isGMT; if (wasGMT != sIsGMT) { arch_rtc_set_system_time_offset(sRealTimeData, - arch_rtc_get_system_time_offset(sRealTimeData) + (((sIsGMT) ? 1 : -1) - * sTimezoneOffset)); + arch_rtc_get_system_time_offset(sRealTimeData) + + (sIsGMT ? 1 : -1) * sTimezoneOffset); } return B_OK; @@ -316,12 +316,19 @@ _user_set_tzfilename(const char *filename, size_t length, bool isGMT) status_t -_user_get_tzfilename(char *filename, size_t length, bool *_isGMT) +_user_get_tzfilename(char *userFilename, size_t length, bool *_userIsGMT) { - if (filename == NULL || _isGMT == NULL - || !IS_USER_ADDRESS(filename) || !IS_USER_ADDRESS(_isGMT) - || user_strlcpy(filename, sTimezoneFilename, length) < B_OK - || user_memcpy(_isGMT, &sIsGMT, sizeof(bool)) < B_OK) + if ((userFilename == NULL || length == 0) && _userIsGMT == NULL) + return B_BAD_VALUE; + + if (userFilename != NULL + && (!IS_USER_ADDRESS(userFilename) + || user_strlcpy(userFilename, sTimezoneFilename, length) < 0)) + return B_BAD_ADDRESS; + + if (_userIsGMT != NULL + && (!IS_USER_ADDRESS(_userIsGMT) + || user_memcpy(_userIsGMT, &sIsGMT, sizeof(bool)) != B_OK)) return B_BAD_ADDRESS; return B_OK;