3 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
10 #include <ac/stdlib.h>
11 #include <ac/string.h>
12 #include <ac/unistd.h>
22 #include <ldap_defaults.h>
28 char* lutil_progname( const char* name, int argc, char *argv[] )
39 for (i=0; i<argc; i++) __etoa(argv[i]);
43 progname = strrchr ( argv[0], *LDAP_DIRSEP );
44 progname = progname ? &progname[1] : argv[0];
50 size_t lutil_gentime( char *s, size_t smax, const struct tm *tm )
54 /* We've been compiling in ASCII so far, but we want EBCDIC now since
55 * strftime only understands EBCDIC input.
57 #pragma convlit(suspend)
59 ret = strftime( s, smax, "%Y%m%d%H%M%SZ", tm );
61 #pragma convlit(resume)
68 size_t lutil_localtime( char *s, size_t smax, const struct tm *tm, long delta )
73 if ( smax < 16 ) { /* YYYYmmddHHMMSSZ */
78 /* We've been compiling in ASCII so far, but we want EBCDIC now since
79 * strftime only understands EBCDIC input.
81 #pragma convlit(suspend)
83 ret = strftime( s, smax, "%Y%m%d%H%M%SZ", tm );
85 #pragma convlit(resume)
88 if ( delta == 0 || ret == 0 ) {
92 if ( smax < 20 ) { /* YYYYmmddHHMMSS+HHMM */
106 snprintf( p, smax - 15, "%02ld%02ld", delta / 3600,
107 ( delta % 3600 ) / 60 );
113 /* strcopy is like strcpy except it returns a pointer to the trailing NUL of
114 * the result string. This allows fast construction of catenated strings
115 * without the overhead of strlen/strcat.
126 while ((*a++ = *b++)) ;
130 /* strncopy is like strcpy except it returns a pointer to the trailing NUL of
131 * the result string. This allows fast construction of catenated strings
132 * without the overhead of strlen/strcat.
141 if (!a || !b || n == 0)
144 while ((*a++ = *b++) && n-- > 0) ;
149 int mkstemp( char * template )
152 return open ( mktemp ( template ), O_RDWR|O_CREAT|O_EXCL, 0600 );