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>
38 /* Some Windows versions accept both forward and backslashes in
39 * directory paths, but we always use backslashes when generating
42 void lutil_slashpath( char *path )
47 while (( c=strchr( p, '/' ))) {
54 char* lutil_progname( const char* name, int argc, char *argv[] )
65 for (i=0; i<argc; i++) __etoa(argv[i]);
69 LUTIL_SLASHPATH( argv[0] );
70 progname = strrchr ( argv[0], *LDAP_DIRSEP );
71 progname = progname ? &progname[1] : argv[0];
76 size_t lutil_gentime( char *s, size_t smax, const struct tm *tm )
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 );
87 #pragma convlit(resume)
94 size_t lutil_localtime( char *s, size_t smax, const struct tm *tm, long delta )
99 if ( smax < 16 ) { /* YYYYmmddHHMMSSZ */
104 /* We've been compiling in ASCII so far, but we want EBCDIC now since
105 * strftime only understands EBCDIC input.
107 #pragma convlit(suspend)
109 ret = strftime( s, smax, "%Y%m%d%H%M%SZ", tm );
111 #pragma convlit(resume)
114 if ( delta == 0 || ret == 0 ) {
118 if ( smax < 20 ) { /* YYYYmmddHHMMSS+HHMM */
132 snprintf( p, smax - 15, "%02ld%02ld", delta / 3600,
133 ( delta % 3600 ) / 60 );
139 /* strcopy 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.
152 while ((*a++ = *b++)) ;
156 /* strncopy is like strcpy except it returns a pointer to the trailing NUL of
157 * the result string. This allows fast construction of catenated strings
158 * without the overhead of strlen/strcat.
167 if (!a || !b || n == 0)
170 while ((*a++ = *b++) && n-- > 0) ;
175 int mkstemp( char * template )
178 return open ( mktemp ( template ), O_RDWR|O_CREAT|O_EXCL, 0600 );