summaryrefslogtreecommitdiff
path: root/source4/lib
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2004-05-25 13:57:39 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:56:14 -0500
commit579c13da43d5b40ac6d6c1436399fbc1d8dfd054 (patch)
tree42299570746f2d7f80356b689cb15e3db6c53d3c /source4/lib
parent81e8de9ca85fe9a6658beb1dab0d231c13cda063 (diff)
downloadsamba-579c13da43d5b40ac6d6c1436399fbc1d8dfd054.tar.gz
samba-579c13da43d5b40ac6d6c1436399fbc1d8dfd054.tar.bz2
samba-579c13da43d5b40ac6d6c1436399fbc1d8dfd054.zip
r873: converted samba4 to use real 64 bit integers instead of
structures. This was suggested by metze recently. I checked on the build farm and all the machines we have support 64 bit ints, and support the LL suffix for 64 bit constants. I suspect some won't support strtoll() and related functions, so we will probably need replacements for those. (This used to be commit 9a9244a1c66654c12abe4379661cba83a73c4c21)
Diffstat (limited to 'source4/lib')
-rw-r--r--source4/lib/fsusage.c18
-rw-r--r--source4/lib/ldb/common/ldb_msg.c22
-rw-r--r--source4/lib/registry/reg_backend_nt4/reg_backend_nt4.c3
-rw-r--r--source4/lib/system.c30
-rw-r--r--source4/lib/time.c99
5 files changed, 55 insertions, 117 deletions
diff --git a/source4/lib/fsusage.c b/source4/lib/fsusage.c
index bb7cff0645..bff6fdda03 100644
--- a/source4/lib/fsusage.c
+++ b/source4/lib/fsusage.c
@@ -24,7 +24,7 @@
/* Return the number of TOSIZE-byte blocks used by
BLOCKS FROMSIZE-byte blocks, rounding away from zero.
*/
-static SMB_BIG_UINT adjust_blocks(SMB_BIG_UINT blocks, SMB_BIG_UINT fromsize, SMB_BIG_UINT tosize)
+static uint64_t adjust_blocks(uint64_t blocks, uint64_t fromsize, uint64_t tosize)
{
if (fromsize == tosize) /* e.g., from 512 to 512 */
return blocks;
@@ -40,10 +40,10 @@ static SMB_BIG_UINT adjust_blocks(SMB_BIG_UINT blocks, SMB_BIG_UINT fromsize, SM
results are returned in *dfree and *dsize, in 512 byte units
*/
-int sys_fsusage(const char *path, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
+int sys_fsusage(const char *path, uint64_t *dfree, uint64_t *dsize)
{
#ifdef STAT_STATFS3_OSF1
-#define CONVERT_BLOCKS(B) adjust_blocks ((SMB_BIG_UINT)(B), (SMB_BIG_UINT)fsd.f_fsize, (SMB_BIG_UINT)512)
+#define CONVERT_BLOCKS(B) adjust_blocks ((uint64_t)(B), (uint64_t)fsd.f_fsize, (uint64_t)512)
struct statfs fsd;
if (statfs (path, &fsd, sizeof (struct statfs)) != 0)
@@ -51,7 +51,7 @@ int sys_fsusage(const char *path, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
#endif /* STAT_STATFS3_OSF1 */
#ifdef STAT_STATFS2_FS_DATA /* Ultrix */
-#define CONVERT_BLOCKS(B) adjust_blocks ((SMB_BIG_UINT)(B), (SMB_BIG_UINT)1024, (SMB_BIG_UINT)512)
+#define CONVERT_BLOCKS(B) adjust_blocks ((uint64_t)(B), (uint64_t)1024, (uint64_t)512)
struct fs_data fsd;
if (statfs (path, &fsd) != 1)
@@ -62,7 +62,7 @@ int sys_fsusage(const char *path, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
#endif /* STAT_STATFS2_FS_DATA */
#ifdef STAT_STATFS2_BSIZE /* 4.3BSD, SunOS 4, HP-UX, AIX */
-#define CONVERT_BLOCKS(B) adjust_blocks ((SMB_BIG_UINT)(B), (SMB_BIG_UINT)fsd.f_bsize, (SMB_BIG_UINT)512)
+#define CONVERT_BLOCKS(B) adjust_blocks ((uint64_t)(B), (uint64_t)fsd.f_bsize, (uint64_t)512)
struct statfs fsd;
if (statfs (path, &fsd) < 0)
@@ -84,7 +84,7 @@ int sys_fsusage(const char *path, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
#ifdef STAT_STATFS2_FSIZE /* 4.4BSD */
-#define CONVERT_BLOCKS(B) adjust_blocks ((SMB_BIG_UINT)(B), (SMB_BIG_UINT)fsd.f_fsize, (SMB_BIG_UINT)512)
+#define CONVERT_BLOCKS(B) adjust_blocks ((uint64_t)(B), (uint64_t)fsd.f_fsize, (uint64_t)512)
struct statfs fsd;
@@ -94,12 +94,12 @@ int sys_fsusage(const char *path, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
#ifdef STAT_STATFS4 /* SVR3, Dynix, Irix, AIX */
# if _AIX || defined(_CRAY)
-# define CONVERT_BLOCKS(B) adjust_blocks ((SMB_BIG_UINT)(B), (SMB_BIG_UINT)fsd.f_bsize, (SMB_BIG_UINT)512)
+# define CONVERT_BLOCKS(B) adjust_blocks ((uint64_t)(B), (uint64_t)fsd.f_bsize, (uint64_t)512)
# ifdef _CRAY
# define f_bavail f_bfree
# endif
# else
-# define CONVERT_BLOCKS(B) ((SMB_BIG_UINT)B)
+# define CONVERT_BLOCKS(B) ((uint64_t)B)
# ifndef _SEQUENT_ /* _SEQUENT_ is DYNIX/ptx */
# ifndef DOLPHIN /* DOLPHIN 3.8.alfa/7.18 has f_bavail */
# define f_bavail f_bfree
@@ -119,7 +119,7 @@ int sys_fsusage(const char *path, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
#if defined(STAT_STATVFS) || defined(STAT_STATVFS64) /* SVR4 */
# define CONVERT_BLOCKS(B) \
- adjust_blocks ((SMB_BIG_UINT)(B), fsd.f_frsize ? (SMB_BIG_UINT)fsd.f_frsize : (SMB_BIG_UINT)fsd.f_bsize, (SMB_BIG_UINT)512)
+ adjust_blocks ((uint64_t)(B), fsd.f_frsize ? (uint64_t)fsd.f_frsize : (uint64_t)fsd.f_bsize, (uint64_t)512)
#ifdef STAT_STATVFS64
struct statvfs64 fsd;
diff --git a/source4/lib/ldb/common/ldb_msg.c b/source4/lib/ldb/common/ldb_msg.c
index 59d480a33a..055569b0ee 100644
--- a/source4/lib/ldb/common/ldb_msg.c
+++ b/source4/lib/ldb/common/ldb_msg.c
@@ -235,6 +235,28 @@ unsigned int ldb_msg_find_uint(const struct ldb_message *msg,
return strtoul(v->data, NULL, 0);
}
+int64_t ldb_msg_find_int64(const struct ldb_message *msg,
+ const char *attr_name,
+ int64_t default_value)
+{
+ const struct ldb_val *v = ldb_msg_find_ldb_val(msg, attr_name);
+ if (!v || !v->data) {
+ return default_value;
+ }
+ return strtoll(v->data, NULL, 0);
+}
+
+uint64_t ldb_msg_find_uint64(const struct ldb_message *msg,
+ const char *attr_name,
+ uint64_t default_value)
+{
+ const struct ldb_val *v = ldb_msg_find_ldb_val(msg, attr_name);
+ if (!v || !v->data) {
+ return default_value;
+ }
+ return strtoull(v->data, NULL, 0);
+}
+
double ldb_msg_find_double(const struct ldb_message *msg,
const char *attr_name,
double default_value)
diff --git a/source4/lib/registry/reg_backend_nt4/reg_backend_nt4.c b/source4/lib/registry/reg_backend_nt4/reg_backend_nt4.c
index e4f9447488..415f764f61 100644
--- a/source4/lib/registry/reg_backend_nt4/reg_backend_nt4.c
+++ b/source4/lib/registry/reg_backend_nt4/reg_backend_nt4.c
@@ -608,8 +608,7 @@ static KEY_SEC_DESC *nt_create_init_sec(REG_HANDLE *h)
#define REG_HANDLE_REGTYPE_NT 1
#define REG_HANDLE_REGTYPE_W9X 2
-#define TTTONTTIME(r, t1, t2) (r)->last_mod_time.low = (t1); \
- (r)->last_mod_time.high = (t2);
+#define TTTONTTIME(r, t1, t2) (r)->last_mod_time = (t1) | (((uint64_t)(t2)) << 32)
#define REGF_HDR_BLKSIZ 0x1000
diff --git a/source4/lib/system.c b/source4/lib/system.c
index 98d975aa50..8c9627eb26 100644
--- a/source4/lib/system.c
+++ b/source4/lib/system.c
@@ -248,36 +248,6 @@ SMB_OFF_T sys_lseek(int fd, SMB_OFF_T offset, int whence)
}
/*******************************************************************
- An fseek() wrapper that will deal with 64 bit filesizes.
-********************************************************************/
-
-int sys_fseek(FILE *fp, SMB_OFF_T offset, int whence)
-{
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(LARGE_SMB_OFF_T) && defined(HAVE_FSEEK64)
- return fseek64(fp, offset, whence);
-#elif defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(LARGE_SMB_OFF_T) && defined(HAVE_FSEEKO64)
- return fseeko64(fp, offset, whence);
-#else
- return fseek(fp, offset, whence);
-#endif
-}
-
-/*******************************************************************
- An ftell() wrapper that will deal with 64 bit filesizes.
-********************************************************************/
-
-SMB_OFF_T sys_ftell(FILE *fp)
-{
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(LARGE_SMB_OFF_T) && defined(HAVE_FTELL64)
- return (SMB_OFF_T)ftell64(fp);
-#elif defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(LARGE_SMB_OFF_T) && defined(HAVE_FTELLO64)
- return (SMB_OFF_T)ftello64(fp);
-#else
- return (SMB_OFF_T)ftell(fp);
-#endif
-}
-
-/*******************************************************************
A creat() wrapper that will deal with 64 bit filesizes.
********************************************************************/
diff --git a/source4/lib/time.c b/source4/lib/time.c
index ba650668c5..e3811c884e 100644
--- a/source4/lib/time.c
+++ b/source4/lib/time.c
@@ -23,11 +23,10 @@
#include "includes.h"
#ifndef TIME_T_MIN
-#define TIME_T_MIN ((time_t)0 < (time_t) -1 ? (time_t) 0 \
- : ~ (time_t) 0 << (sizeof (time_t) * 8 - 1))
+#define TIME_T_MIN 0
#endif
#ifndef TIME_T_MAX
-#define TIME_T_MAX (~ (time_t) 0 - TIME_T_MIN)
+#define TIME_T_MAX (~(time_t)0)
#endif
/*******************************************************************
@@ -84,35 +83,23 @@ int get_time_zone(time_t t)
return tm_diff(&tm_utc,tm);
}
-#define TIME_FIXUP_CONSTANT (369.0*365.25*24*60*60-(3.0*24*60*60+6.0*60*60))
+#define TIME_FIXUP_CONSTANT 11644473600LL
/****************************************************************************
interpret an 8 byte "filetime" structure to a time_t
It's originally in "100ns units since jan 1st 1601"
****************************************************************************/
-time_t nt_time_to_unix(const NTTIME *nt)
+time_t nt_time_to_unix(NTTIME nt)
{
- double d;
- time_t ret;
+ nt += 1000*1000*10/2;
+ nt /= 1000*1000*10;
+ nt -= TIME_FIXUP_CONSTANT;
- if (nt->high == 0) {
+ if (TIME_T_MIN >= nt || nt >= TIME_T_MAX) {
return 0;
}
- d = ((double)nt->high)*4.0*(double)(1<<30);
- d += (nt->low&0xFFF00000);
- d *= 1.0e-7;
-
- /* now adjust by 369 years to make the secs since 1970 */
- d -= TIME_FIXUP_CONSTANT;
-
- if (TIME_T_MIN >= d || d >= TIME_T_MAX) {
- return 0;
- }
-
- ret = (time_t)(d+0.5);
-
- return ret;
+ return (time_t)nt;
}
@@ -122,30 +109,22 @@ This takes GMT as input
****************************************************************************/
void unix_to_nt_time(NTTIME *nt, time_t t)
{
- double d;
+ uint64_t t2;
- if (t==0) {
- nt->low = 0;
- nt->high = 0;
- return;
- }
- if (t == TIME_T_MAX) {
- nt->low = 0xffffffff;
- nt->high = 0x7fffffff;
+ if (t == (time_t)-1) {
+ *nt = (NTTIME)-1LL;
return;
}
- if (t == -1) {
- nt->low = 0xffffffff;
- nt->high = 0xffffffff;
+ if (t == 0) {
+ *nt = 0;
return;
}
- d = (double)(t);
- d += TIME_FIXUP_CONSTANT;
- d *= 1.0e7;
+ t2 = t;
+ t2 += TIME_FIXUP_CONSTANT;
+ t2 *= 1000*1000*10;
- nt->high = (uint32)(d * (1.0/(4.0*(double)(1<<30))));
- nt->low = (uint32)(d - ((double)nt->high)*4.0*(double)(1<<30));
+ *nt = t2;
}
@@ -390,18 +369,10 @@ char *timestring(TALLOC_CTX *mem_ctx, time_t t)
return TimeBuf;
}
-/****************************************************************************
-check if NTTIME is 0
-****************************************************************************/
-BOOL nt_time_is_zero(NTTIME *nt)
-{
- return (nt->high==0);
-}
-
/*
return a talloced string representing a NTTIME for human consumption
*/
-const char *nt_time_string(TALLOC_CTX *mem_ctx, const NTTIME *nt)
+const char *nt_time_string(TALLOC_CTX *mem_ctx, NTTIME nt)
{
time_t t = nt_time_to_unix(nt);
return talloc_strdup(mem_ctx, timestring(mem_ctx, t));
@@ -411,10 +382,9 @@ const char *nt_time_string(TALLOC_CTX *mem_ctx, const NTTIME *nt)
/*
put a NTTIME into a packet
*/
-void push_nttime(void *base, uint16 offset, NTTIME *t)
+void push_nttime(void *base, uint16 offset, NTTIME t)
{
- SIVAL(base, offset, t->low);
- SIVAL(base, offset+4, t->high);
+ SBVAL(base, offset, t);
}
/*
@@ -422,30 +392,7 @@ void push_nttime(void *base, uint16 offset, NTTIME *t)
*/
NTTIME pull_nttime(void *base, uint16 offset)
{
- NTTIME ret;
- ret.low = IVAL(base, offset);
- ret.high = IVAL(base, offset+4);
- return ret;
-}
-
-/*
- convert a NTTIME to a double in 100-nano-seconds since 1601
-*/
-double nttime_to_double_nt(NTTIME t)
-{
- const double t32 = 4294967296.0;
- return t.high*t32 + t.low;
-}
-
-/*
- convert a double in 100-nano-seconds since 1601 to a NTTIME
-*/
-NTTIME nttime_from_double_nt(double t)
-{
- const double t32 = 4294967296.0;
- NTTIME ret;
- ret.high = t / t32;
- ret.low = t - (ret.high*t32);
+ NTTIME ret = BVAL(base, offset);
return ret;
}
@@ -454,5 +401,5 @@ NTTIME nttime_from_double_nt(double t)
*/
NTTIME nttime_from_string(const char *s)
{
- return nttime_from_double_nt(strtod(s, NULL));
+ return strtoull(s, NULL, 0);
}