2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2004 The OpenLDAP Foundation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
11 * A copy of this license is available in the file LICENSE in the
12 * top-level directory of the distribution or, alternatively, at
13 * <http://www.OpenLDAP.org/license.html>.
19 #include <ac/stdlib.h>
20 #include <ac/string.h>
21 #include <ac/unistd.h>
31 #include <ldap_defaults.h>
37 char* lutil_progname( const char* name, int argc, char *argv[] )
48 for (i=0; i<argc; i++) __etoa(argv[i]);
52 progname = strrchr ( argv[0], *LDAP_DIRSEP );
53 progname = progname ? &progname[1] : argv[0];
59 size_t lutil_gentime( char *s, size_t smax, const struct tm *tm )
63 /* We've been compiling in ASCII so far, but we want EBCDIC now since
64 * strftime only understands EBCDIC input.
66 #pragma convlit(suspend)
68 ret = strftime( s, smax, "%Y%m%d%H%M%SZ", tm );
70 #pragma convlit(resume)
77 size_t lutil_localtime( char *s, size_t smax, const struct tm *tm, long delta )
82 if ( smax < 16 ) { /* YYYYmmddHHMMSSZ */
87 /* We've been compiling in ASCII so far, but we want EBCDIC now since
88 * strftime only understands EBCDIC input.
90 #pragma convlit(suspend)
92 ret = strftime( s, smax, "%Y%m%d%H%M%SZ", tm );
94 #pragma convlit(resume)
97 if ( delta == 0 || ret == 0 ) {
101 if ( smax < 20 ) { /* YYYYmmddHHMMSS+HHMM */
115 snprintf( p, smax - 15, "%02ld%02ld", delta / 3600,
116 ( delta % 3600 ) / 60 );
122 /* strcopy is like strcpy except it returns a pointer to the trailing NUL of
123 * the result string. This allows fast construction of catenated strings
124 * without the overhead of strlen/strcat.
135 while ((*a++ = *b++)) ;
139 /* strncopy is like strcpy except it returns a pointer to the trailing NUL of
140 * the result string. This allows fast construction of catenated strings
141 * without the overhead of strlen/strcat.
150 if (!a || !b || n == 0)
153 while ((*a++ = *b++) && n-- > 0) ;
158 int mkstemp( char * template )
161 return open ( mktemp ( template ), O_RDWR|O_CREAT|O_EXCL, 0600 );