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];
49 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)
66 return lutil_localtime( s, smax, tm, 0 );
70 size_t lutil_localtime( char *s, size_t smax, const struct tm *tm, long delta )
80 /* We've been compiling in ASCII so far, but we want EBCDIC now since
81 * strftime only understands EBCDIC input.
83 #pragma convlit(suspend)
85 ret = strftime( s, smax, "%Y%m%d%H%M%SZ", tm );
104 snprintf( p, smax - 15, "%02ld%02ld", delta / 3600,
105 ( delta % 3600 ) / 60 );
108 #pragma convlit(resume)
115 /* strcopy is like strcpy except it returns a pointer to the trailing NUL of
116 * the result string. This allows fast construction of catenated strings
117 * without the overhead of strlen/strcat.
128 while ((*a++ = *b++)) ;
132 /* strncopy is like strcpy except it returns a pointer to the trailing NUL of
133 * the result string. This allows fast construction of catenated strings
134 * without the overhead of strlen/strcat.
143 if (!a || !b || n == 0)
146 while ((*a++ = *b++) && n-- > 0) ;
151 int mkstemp( char * template )
154 return open ( mktemp ( template ), O_RDWR|O_CREAT|O_EXCL, 0600 );