1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
1999-08-18 03:00:59 +08:00
|
|
|
/*
|
2002-01-05 05:17:25 +08:00
|
|
|
* Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
|
1999-08-18 03:00:59 +08:00
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <ac/stdlib.h>
|
|
|
|
#include <ac/string.h>
|
2001-12-18 10:54:49 +08:00
|
|
|
#include <ac/unistd.h>
|
2002-07-27 08:25:16 +08:00
|
|
|
#include <ac/time.h>
|
2001-12-18 12:52:55 +08:00
|
|
|
#ifdef HAVE_IO_H
|
|
|
|
#include <io.h>
|
|
|
|
#endif
|
2001-12-18 10:48:20 +08:00
|
|
|
#ifdef HAVE_FCNTL_H
|
|
|
|
#include <fcntl.h>
|
|
|
|
#endif
|
1999-08-18 03:00:59 +08:00
|
|
|
|
|
|
|
#include <lutil.h>
|
|
|
|
#include <ldap_defaults.h>
|
|
|
|
|
2002-07-27 08:25:16 +08:00
|
|
|
#ifdef HAVE_EBCDIC
|
|
|
|
int _trans_argv = 1;
|
|
|
|
#endif
|
|
|
|
|
1999-08-18 03:00:59 +08:00
|
|
|
char* lutil_progname( const char* name, int argc, char *argv[] )
|
|
|
|
{
|
|
|
|
char *progname;
|
|
|
|
|
|
|
|
if(argc == 0) {
|
2002-07-27 08:25:16 +08:00
|
|
|
return (char *)name;
|
1999-08-18 03:00:59 +08:00
|
|
|
}
|
|
|
|
|
2002-07-27 08:25:16 +08:00
|
|
|
#ifdef HAVE_EBCDIC
|
|
|
|
if (_trans_argv) {
|
|
|
|
int i;
|
|
|
|
for (i=0; i<argc; i++) __etoa(argv[i]);
|
|
|
|
_trans_argv = 0;
|
|
|
|
}
|
|
|
|
#endif
|
1999-08-18 03:00:59 +08:00
|
|
|
progname = strrchr ( argv[0], *LDAP_DIRSEP );
|
2002-07-27 08:25:16 +08:00
|
|
|
progname = progname ? &progname[1] : argv[0];
|
1999-08-18 03:00:59 +08:00
|
|
|
|
|
|
|
return progname;
|
|
|
|
}
|
2001-06-15 12:16:55 +08:00
|
|
|
|
2002-07-27 08:25:16 +08:00
|
|
|
size_t lutil_gentime( char *s, size_t max, const struct tm *tm )
|
2001-06-15 12:16:55 +08:00
|
|
|
{
|
2002-07-27 08:25:16 +08:00
|
|
|
size_t ret;
|
|
|
|
#ifdef HAVE_EBCDIC
|
|
|
|
/* We've been compiling in ASCII so far, but we want EBCDIC now since
|
|
|
|
* strftime only understands EBCDIC input.
|
|
|
|
*/
|
|
|
|
#pragma convlit(suspend)
|
2001-12-18 10:54:49 +08:00
|
|
|
#endif
|
2002-07-27 08:25:16 +08:00
|
|
|
ret = strftime( s, max, "%Y%m%d%H%M%SZ", tm );
|
|
|
|
#ifdef HAVE_EBCDIC
|
|
|
|
#pragma convlit(resume)
|
|
|
|
__etoa( s );
|
2001-10-11 12:01:45 +08:00
|
|
|
#endif
|
2002-07-27 08:25:16 +08:00
|
|
|
return ret;
|
|
|
|
}
|
2002-07-20 01:33:14 +08:00
|
|
|
|
2002-07-27 08:25:16 +08:00
|
|
|
/* strcopy is like strcpy except it returns a pointer to the trailing NUL of
|
|
|
|
* the result string. This allows fast construction of catenated strings
|
|
|
|
* without the overhead of strlen/strcat.
|
2002-07-20 01:33:14 +08:00
|
|
|
*/
|
2002-07-27 08:25:16 +08:00
|
|
|
char *
|
|
|
|
lutil_strcopy(
|
|
|
|
char *a,
|
|
|
|
const char *b
|
|
|
|
)
|
2002-07-20 01:33:14 +08:00
|
|
|
{
|
2002-07-27 08:25:16 +08:00
|
|
|
if (!a || !b)
|
|
|
|
return a;
|
|
|
|
|
|
|
|
while ((*a++ = *b++)) ;
|
|
|
|
return a-1;
|
2002-07-20 01:33:14 +08:00
|
|
|
}
|
|
|
|
|
2002-07-27 08:25:16 +08:00
|
|
|
/* strncopy is like strcpy except it returns a pointer to the trailing NUL of
|
|
|
|
* the result string. This allows fast construction of catenated strings
|
|
|
|
* without the overhead of strlen/strcat.
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
lutil_strncopy(
|
|
|
|
char *a,
|
|
|
|
const char *b,
|
|
|
|
size_t n
|
|
|
|
)
|
2002-07-20 01:33:14 +08:00
|
|
|
{
|
2002-07-27 08:25:16 +08:00
|
|
|
if (!a || !b || n == 0)
|
|
|
|
return a;
|
|
|
|
|
|
|
|
while ((*a++ = *b++) && n-- > 0) ;
|
|
|
|
return a-1;
|
|
|
|
}
|
2002-07-20 01:33:14 +08:00
|
|
|
|
2002-07-27 08:25:16 +08:00
|
|
|
#ifndef HAVE_MKSTEMP
|
|
|
|
int mkstemp( char * template )
|
|
|
|
{
|
|
|
|
#ifdef HAVE_MKTEMP
|
|
|
|
return open ( mktemp ( template ), O_RDWR|O_CREAT|O_EXCL, 0600 );
|
|
|
|
#else
|
|
|
|
return -1;
|
|
|
|
#endif
|
2002-07-20 01:33:14 +08:00
|
|
|
}
|
2002-07-27 08:25:16 +08:00
|
|
|
#endif
|