first commit
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
#
|
||||
# ma_muquit@fccc.edu
|
||||
# jul-29-199
|
||||
#
|
||||
|
||||
CC= gcc
|
||||
DEFS= -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_STRING_H=1 -DHAVE_STRINGS_H=1 -DHAVE_MEMORY_H=1 -DHAVE_MALLOC_H=1 -DHAVE_UNISTD_H=1 -DHAVE_CTYPE_H=1 -DHAVE_STDINT_H=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_STDLIB_H=1 -DHAVE_FCNTL_H=1 -DHAVE_SYS_FILE_H=1 -DHAVE_FLOCK=1 -DHAVE_SOCKET=1 -DHAVE_HTONL=1 -DHAVE_GETHOSTNAME=1 -DHAVE_GETHOSTBYADDR=1 -DHAVE_YP_GET_DEFAULT_DOMAIN=1 -DHAVE_LIBNSL=1 -DHAVE_RES_SEARCH=1 -DHAVE_LIBRESOLV=1 -DHAVE_INET_ATON=1 -DHAVE_DN_SKIPNAME=1 -DHAVE_MKSTEMP=1 -DHAVE_OPENSSL=1
|
||||
AR= ar cq
|
||||
RANLIB= ranlib
|
||||
LIBNAME= libmutils.a
|
||||
|
||||
INCLUDES= -I. -I/usr/include/malloc
|
||||
|
||||
# replace -O with -g in order to debug
|
||||
|
||||
DEFINES= $(INCLUDES) $(DEFS) -DSYS_UNIX=1
|
||||
CFLAGS= -O $(DEFINES)
|
||||
|
||||
SRCS = string.c mutils.c mime.c
|
||||
OBJS = string.o mutils.o mime.o
|
||||
|
||||
.c.o:
|
||||
rm -f $@
|
||||
$(CC) $(CFLAGS) -c $*.c
|
||||
|
||||
all: $(LIBNAME)
|
||||
|
||||
$(LIBNAME): $(OBJS)
|
||||
rm -f $@
|
||||
$(AR) $@ $(OBJS)
|
||||
$(RANLIB) $@
|
||||
|
||||
clean:
|
||||
rm -f $(OBJS) $(LIBNAME) core
|
||||
@@ -0,0 +1,9 @@
|
||||
A utility library. All the functions starts with mtutils, for example:
|
||||
mutilsSafeStrcpy(), mutilsMalloc() etc. The library can be compiled with
|
||||
an ANSI or non-ANSI C compiler.
|
||||
|
||||
/* ANSIfiled, muquit@muquit.com, Mar-27-2001 */
|
||||
|
||||
--
|
||||
Muhammad Muquit
|
||||
Jul-29-199
|
||||
@@ -0,0 +1,20 @@
|
||||
#include "mutils.h"
|
||||
#include <string.h>
|
||||
|
||||
int main (int argc,char **argv)
|
||||
{
|
||||
char
|
||||
*s=NULL;
|
||||
int
|
||||
i;
|
||||
|
||||
if (argc != 2)
|
||||
{
|
||||
(void) fprintf(stderr,"usage: %s <string>\n",argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
s=strdup(argv[1]);
|
||||
(void) fprintf(stderr,"MD5(%s) %s\n",s,getMD5Digest(s));
|
||||
|
||||
return(0);
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
#include "mutils.h"
|
||||
|
||||
static char base64_chars[64] =
|
||||
{
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
|
||||
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd',
|
||||
'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
|
||||
't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9', '+', '/'
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** generateBoundary()
|
||||
** generate unuque string for boundary for MIME tag
|
||||
**
|
||||
** Parameters:
|
||||
** char *boundary - NULL terminated boundary string - returns
|
||||
** int len - size of boundary (malloc'd or static)
|
||||
**
|
||||
** Return Values:
|
||||
** none
|
||||
**
|
||||
** Limitations and Comments:
|
||||
** boundary must have len bytes in it to store the boundary. the
|
||||
functio
|
||||
n
|
||||
** calls rand() for random number, so the caller should call srand()
|
||||
** before calling this function.
|
||||
**
|
||||
** This function is adapted from mutt code.
|
||||
**
|
||||
** Development History:
|
||||
** who when why
|
||||
** muquit@muquit.com Mar-06-2002 needs MIME support
|
||||
*/
|
||||
#define BOUNDARY_LEN 16
|
||||
void mutilsGenerateMIMEBoundary(char *boundary,int len)
|
||||
{
|
||||
char
|
||||
*p;
|
||||
int
|
||||
i;
|
||||
memset(boundary,0,len);
|
||||
p=boundary;
|
||||
for (i=0; i < BOUNDARY_LEN; i++)
|
||||
{
|
||||
if (i >= (len-1))
|
||||
break;
|
||||
*p++ = base64_chars[rand() % sizeof(base64_chars)];
|
||||
}
|
||||
*p='\0';
|
||||
}
|
||||
|
||||
static void output64Chunk(int c1,int c2,int c3,int pads, FILE *outfile)
|
||||
{
|
||||
putc(base64_chars[c1>>2], outfile);
|
||||
putc(base64_chars[((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4)], outfile);
|
||||
if (pads == 2)
|
||||
{
|
||||
putc('=', outfile);
|
||||
putc('=', outfile);
|
||||
}
|
||||
else if (pads)
|
||||
{
|
||||
putc(base64_chars[((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6)], outfile);
|
||||
putc('=', outfile);
|
||||
}
|
||||
else
|
||||
{
|
||||
putc(base64_chars[((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6)], outfile);
|
||||
putc(base64_chars[c3 & 0x3F], outfile);
|
||||
}
|
||||
}
|
||||
|
||||
void mutilsBase64Encode(FILE *ifp,FILE *ofp)
|
||||
{
|
||||
int
|
||||
c1,
|
||||
c2,
|
||||
c3,
|
||||
c4,
|
||||
ct=0;
|
||||
|
||||
while ((c1=getc(ifp)) != EOF)
|
||||
{
|
||||
c2=getc(ifp);
|
||||
if (c2 == EOF)
|
||||
{
|
||||
output64Chunk(c1,0,0,2,ofp);
|
||||
}
|
||||
else
|
||||
{
|
||||
c3=getc(ifp);
|
||||
if (c3 == EOF)
|
||||
{
|
||||
output64Chunk(c1,c2,0,1,ofp);
|
||||
}
|
||||
else
|
||||
{
|
||||
output64Chunk(c1,c2,c3,0,ofp);
|
||||
}
|
||||
}
|
||||
ct += 4;
|
||||
if (ct > 71)
|
||||
{
|
||||
putc('\r',ofp); /* qmail fix 15.07.05 (movi) */
|
||||
putc('\n',ofp);
|
||||
ct=0;
|
||||
}
|
||||
}
|
||||
if (ct)
|
||||
{
|
||||
putc('\r',ofp); /* qmail fix 15.07.05 (movi) */
|
||||
putc('\n',ofp);
|
||||
}
|
||||
|
||||
(void) fflush(ofp);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,148 @@
|
||||
#ifndef MUTILS_H
|
||||
#define MUTILS_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#if STDC_HEADERS || HAVE_STRING_H
|
||||
#include <string.h> /* ANSI string.h and pre-ANSI memory.h might conflict*/
|
||||
#if !STDC_HEADERS && HAVE_MEMORY_H
|
||||
#include <memory.h>
|
||||
#endif
|
||||
#else
|
||||
#if HAVE_STRINGS_H
|
||||
#include <strings.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#if HAVE_CTYPE_H
|
||||
#include <ctype.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_SYS_WAIT_H
|
||||
#include <sys/wait.h>
|
||||
#endif
|
||||
|
||||
#if SYS_UNIX
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
#ifdef WINNT
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <io.h>
|
||||
#include <share.h>
|
||||
#define ftruncate chsize
|
||||
#endif
|
||||
|
||||
#if HAVE_SYS_PARAM_H
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_FCNTL_H
|
||||
#ifndef O_RDONLY /* prevent multiple inclusion on lame systems (from
|
||||
vile)*/
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if HAVE_MALLOC_H
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef HAVE_SYS_FILE_H
|
||||
#include <sys/file.h>
|
||||
#endif
|
||||
|
||||
#if TIME_WITH_SYS_TIME
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#else
|
||||
#if HAVE_SYS_TIME_H
|
||||
#include <sys/time.h>
|
||||
#else
|
||||
#include <time.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define MUTILS_CFL __FILE__,__LINE__
|
||||
|
||||
|
||||
#if __STDC__ || defined(sgi) || defined(_AIX)
|
||||
#undef _Declare
|
||||
#define _Declare(formal_parameters) formal_parameters
|
||||
#else
|
||||
#define _Declare(formal_parameters) ()
|
||||
#define const
|
||||
#endif
|
||||
|
||||
#define MUTILS_MAX_TOKEN_LEN 1024
|
||||
|
||||
|
||||
#define MUTILS_CHECK_MALLOC(p) \
|
||||
do \
|
||||
{ \
|
||||
if (p == NULL) \
|
||||
{\
|
||||
(void) fprintf(stderr,"%s (%d) - memory allocation problem\n",__FILE__,__LINE__); \
|
||||
goto ExitProcessing; \
|
||||
}\
|
||||
}while(0)
|
||||
|
||||
|
||||
|
||||
/* function prototypes */
|
||||
void mutilsBase64Encode (FILE *ifp,FILE *ofp);
|
||||
void mutilsGenerateMIMEBoundary(char *boundary,int len);
|
||||
int mutilsParseURL (char *url,char *hostname,
|
||||
int hostname_len, int *port,
|
||||
char *page,int page_len);
|
||||
|
||||
void mutilsStripLeadingSpace (char *s);
|
||||
void mutilsStripTrailingSpace (char *s);
|
||||
char *mutilsReverseString (char *str);
|
||||
char *mutilsStrncat (char *dst,char *src,int n);
|
||||
char *mutilsStrncpy (char *dsr,char *src,int n);
|
||||
int mutilsStrncasecmp (char *s1,char *s2,int n);
|
||||
char *mutilsStrdup (char *str);
|
||||
int mutilsStrcasecmp (char *a,char *b);
|
||||
void mutilsSafeStrcpy (char *dst,char *src,int n);
|
||||
void mutilsSafeStrcat (char *dsr,char *src,int n,int ss,int sl);
|
||||
char *mutilsStrtok (char *s,char *delim);
|
||||
int mutilsHowmanyCommas (char *buf);
|
||||
void mutilsCommaize (char *buf);
|
||||
void mutilsCleanBuf (char *buf,int bufsize,int *length);
|
||||
char *mutilsRmallws (char *str);
|
||||
char *mutilsStristr (char *s,char *t);
|
||||
int mutilsIsinname (char *string,char *mask);
|
||||
char *mutilsGetTime (void);
|
||||
char mutilsChopNL (char *str);
|
||||
int mutilsTmpFilename (char *filename);
|
||||
char *mutilsBasename (char *path);
|
||||
int mutilsWhich (char *name);
|
||||
void mutilsSetLock (int fd);
|
||||
void mutilsDotLock (char *filepath,char *errbuf);
|
||||
void mutilsDotUnlock (int delete);
|
||||
char *mutilsStrUpper (char *str);
|
||||
char *mutilsStrLower (char *str);
|
||||
int mutilsEatComment (FILE *fp);
|
||||
int mutilsEatWhitespace (FILE *fp);
|
||||
char *mutilsGetDirname (char *file);
|
||||
char *mutilsSpacesToChar (char *str,int c);
|
||||
char **mutilsTokenize(char *str,int delim,int *ntokens);
|
||||
void mutilsFreeTokens(char **tokens,int ntokens);
|
||||
unsigned char *mutils_encode_base64(void *src,unsigned long srcl,unsigned long *len);
|
||||
void *mutils_decode_base64(unsigned char *src,unsigned long srcl,unsigned long *len);
|
||||
|
||||
|
||||
#endif /* MUTILS_H */
|
||||
@@ -0,0 +1,510 @@
|
||||
/* all interesting strngs related routines */
|
||||
|
||||
#include <mutils.h>
|
||||
|
||||
|
||||
/*
|
||||
** reverseString()
|
||||
** reverse a string
|
||||
**
|
||||
** Parameters:
|
||||
** char *str string to modify
|
||||
**
|
||||
** Return Values:
|
||||
** pointer to the modified string
|
||||
**
|
||||
** Limitations and Comments:
|
||||
** str is modified
|
||||
** borrowed from c-snippets STRREV.C, public domain by Bob Stout
|
||||
** The name of the function was stttev() -- muquit, May-26-1999
|
||||
**
|
||||
** Development History:
|
||||
** who when why
|
||||
** ma_muquit@fccc.edu may-26-1999 first cut
|
||||
*/
|
||||
|
||||
char *mutilsReverseString(char *str)
|
||||
{
|
||||
char
|
||||
*p1,
|
||||
*p2;
|
||||
|
||||
if (! str || ! *str)
|
||||
return str;
|
||||
|
||||
for (p1=str,p2 =str+strlen(str)-1; p2 > p1; ++p1, --p2)
|
||||
{
|
||||
*p1 ^= *p2;
|
||||
*p2 ^= *p1;
|
||||
*p1 ^= *p2;
|
||||
}
|
||||
return (str);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** mutilsStrncat()
|
||||
** appends at most n characters of src string to dst string
|
||||
**
|
||||
** Parameters:
|
||||
** dst destination string
|
||||
** src source string
|
||||
** n number of character to take from src
|
||||
**
|
||||
**
|
||||
** Return Values:
|
||||
**
|
||||
**
|
||||
** Limitations and Comments:
|
||||
** taken from Henry Spencer's public domain string library
|
||||
**
|
||||
** Development History:
|
||||
** who when why
|
||||
** ma_muquit@fccc.edu Jul-31-1999 first cut
|
||||
*/
|
||||
char *mutilsStrncat(char *dst,char *src,int n)
|
||||
{
|
||||
register char
|
||||
*dscan,
|
||||
*sscan;
|
||||
|
||||
register int
|
||||
count;
|
||||
|
||||
for (dscan=dst; *dscan != '\0'; dscan++)
|
||||
continue;
|
||||
|
||||
sscan=src;
|
||||
count=n;
|
||||
|
||||
while (*sscan != '\0' && --count >= 0)
|
||||
*dscan++ = *sscan++;
|
||||
|
||||
*dscan++ = '\0';
|
||||
|
||||
return (dst);
|
||||
}
|
||||
/*
|
||||
** mutilsStrncpy()
|
||||
** copy at most n characters of string src to dst
|
||||
**
|
||||
** Parameters:
|
||||
** char *dst
|
||||
** char *str
|
||||
** int n
|
||||
**
|
||||
** Return Values:
|
||||
** pinter to the destination string
|
||||
**
|
||||
** Limitations and Comments:
|
||||
** adapted from henry's stringlib
|
||||
**
|
||||
** Development History:
|
||||
** who when why
|
||||
** ma_muquit@fccc.edu Jul-31-1999 first cut
|
||||
*/
|
||||
char *mutilsStrncpy(char *dst,char *src,int n)
|
||||
{
|
||||
register char
|
||||
*dscan;
|
||||
|
||||
register char
|
||||
*sscan;
|
||||
|
||||
register int
|
||||
count;
|
||||
|
||||
dscan=dst;
|
||||
sscan=src;
|
||||
count=n;
|
||||
|
||||
while (--count >= 0 && (*dscan++ = *sscan++) != '\0')
|
||||
continue;
|
||||
|
||||
while (--count >= 0)
|
||||
*dscan++ = '\0';
|
||||
return(dst);
|
||||
}
|
||||
|
||||
/*
|
||||
** mutilsStrdup()
|
||||
** duplicate a sting
|
||||
**
|
||||
** Parameters:
|
||||
** char *string string to duplicate
|
||||
**
|
||||
** Return Values:
|
||||
** pointer to the duplicated stirng. NULL if fails.
|
||||
**
|
||||
** Limitations and Comments:
|
||||
** allocate memory, caller is responsible to free it.
|
||||
**
|
||||
** Development History:
|
||||
** who when why
|
||||
** ma_muquit@fccc.edu Jul-31-1999 first cut
|
||||
*/
|
||||
char *mutilsStrdup(char *string)
|
||||
{
|
||||
char
|
||||
*tmp;
|
||||
|
||||
if (string == NULL || *string == '\0')
|
||||
return ((char *) NULL);
|
||||
|
||||
tmp = (char *) malloc ((int) strlen(string)*sizeof(char)+1 );
|
||||
|
||||
if (tmp == (char *) NULL)
|
||||
{
|
||||
return ((char *) NULL);
|
||||
}
|
||||
/* it's safe to copy this way */
|
||||
(void) strcpy(tmp, string);
|
||||
return (tmp);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** mutilsStrcasecmp()
|
||||
** case insensitive string comparison
|
||||
**
|
||||
** Parameters:
|
||||
** char *a
|
||||
** char *b
|
||||
**
|
||||
** Return Values:
|
||||
** < 0 if a < b
|
||||
** > 0 if a > b
|
||||
** 0 if a = b
|
||||
**
|
||||
** Limitations and Comments:
|
||||
** found somewhere on the net. I didn't write it
|
||||
**
|
||||
** Development History:
|
||||
** who when why
|
||||
** ma_muquit@fccc.edu Jul-31-1999 first cut
|
||||
*/
|
||||
int mutilsStrcasecmp(char *a,char *b)
|
||||
{
|
||||
register char
|
||||
ac,
|
||||
bc;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
ac = *a++;
|
||||
bc = *b++;
|
||||
|
||||
if(ac == 0)
|
||||
{
|
||||
if(bc == 0)
|
||||
return 0;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(bc == 0)
|
||||
return 1;
|
||||
else
|
||||
{
|
||||
if(ac != bc)
|
||||
{
|
||||
if(islower(ac)) ac = toupper(ac);
|
||||
if(islower(bc)) bc = toupper(bc);
|
||||
if( ac != bc )
|
||||
return ac - bc;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
** mutilsStrncasecmp()
|
||||
** case in-sensitive comparison wth first n bytes of fist string
|
||||
**
|
||||
** Parameters:
|
||||
** char *s1
|
||||
* char *s2
|
||||
* int n
|
||||
**
|
||||
** Return Values:
|
||||
**
|
||||
**
|
||||
** Limitations and Comments:
|
||||
** < 0 if first n bytes of a < b
|
||||
** > 0 if first n bytes of a a > b
|
||||
** 0 if first n bytes of a a = b
|
||||
**
|
||||
** Development History:
|
||||
** who when why
|
||||
** ma_muquit@fccc.edu Jul-31-1999 first cut
|
||||
*/
|
||||
int mutilsStrncasecmp(char *s1,char *s2,int n)
|
||||
{
|
||||
register char
|
||||
*scan1,
|
||||
*scan2;
|
||||
|
||||
int
|
||||
count;
|
||||
|
||||
scan1=s1;
|
||||
scan2=s2;
|
||||
count=n;
|
||||
|
||||
while (--count >= 0 && *scan1 != '\0' && tolower(*scan1) == tolower(*scan2))
|
||||
{
|
||||
scan1++;
|
||||
scan2++;
|
||||
}
|
||||
if (count < 0)
|
||||
return (0);
|
||||
|
||||
|
||||
return(tolower(*scan1) - tolower(*scan2));
|
||||
}
|
||||
|
||||
/*
|
||||
** mutilsSafeStrcpy()
|
||||
** copy a string to another safely without overflowing buffer
|
||||
**
|
||||
** RCS
|
||||
** $Revision: 1 $
|
||||
** $Date: 2/24/04 8:38p $
|
||||
** Return Values:
|
||||
** none
|
||||
**
|
||||
** Parameters:
|
||||
** dst destination buffer
|
||||
** src source buffer
|
||||
** n max allowable n of the src
|
||||
**
|
||||
** Side Effects:
|
||||
** if copying is safe, dst buffer is modified.
|
||||
**
|
||||
** Limitations and Comments:
|
||||
** if the source string is longer than n, it's truncated to
|
||||
** n. dst must be static or dynamically allocated buffer, that
|
||||
** is it must be able to hold atleast lenth bytes buffer. The src
|
||||
** is checked if it is NULL or not. if NULL the routine will exit
|
||||
** after writing an error message image.
|
||||
**
|
||||
**
|
||||
** Development History:
|
||||
** who when why
|
||||
** ma_muquit@fccc.edu Oct-17-1997 first cut
|
||||
*/
|
||||
void mutilsSafeStrcpy(char *dst,char *src,int n)
|
||||
{
|
||||
/* now copy */
|
||||
/*
|
||||
(void) mutilsStrncpy(dst,src,n);
|
||||
*/
|
||||
(void) strncpy(dst,src,n);
|
||||
dst[n]='\0';
|
||||
}
|
||||
|
||||
/*
|
||||
* mutilsSafeStrcat()
|
||||
* safely appends one string to another without overflowing the source
|
||||
* buffer.
|
||||
*
|
||||
* Parameters:
|
||||
* dst appends with this string
|
||||
* src string to append
|
||||
* length first this many character of src to append
|
||||
* ssc_size maximum size of destination string
|
||||
* ssc_length length of string in destination buffer
|
||||
*
|
||||
* Return Values:
|
||||
* none
|
||||
*
|
||||
* Limitations and Comments:
|
||||
* dst must have enough space staically or dynamically allocated
|
||||
* before calling. Need to provide a portable strncat() as matt
|
||||
* suggested that some versions of strncat (e.g. solaris 2.5.1) write
|
||||
* at most n+1 characters past the end of s1 and then replace the
|
||||
* n+1st character with a '\0';
|
||||
*
|
||||
*
|
||||
* Development History:
|
||||
* who when why
|
||||
* ma_muquit@fccc.edu Oct-1997 first cut
|
||||
* mhpower@mit.edu Nov-03-1997 fixed
|
||||
*/
|
||||
void mutilsSafeStrcat(char *dst,char *src,int length,int ssc_size,
|
||||
int ssc_length)
|
||||
{
|
||||
int copy_length;
|
||||
|
||||
if ( NULL == src )
|
||||
{
|
||||
/*
|
||||
StringImage("Source buffer is NULL in safeStrcat()!");
|
||||
*/
|
||||
(void) fprintf(stderr,"Source buffer is NULL in safeStrcat()!\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (strlen(src) >= ssc_size - ssc_length)
|
||||
{
|
||||
/*
|
||||
StringImage("buffer overflow detected! aborting");
|
||||
*/
|
||||
(void) fprintf(stderr,"buffer overflow detected! aborting\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (length < ssc_size - ssc_length)
|
||||
{
|
||||
copy_length = length;
|
||||
}
|
||||
else
|
||||
{
|
||||
copy_length = ssc_size - ssc_length;
|
||||
}
|
||||
|
||||
/* now copy */
|
||||
(void) mutilsStrncat(dst,src,copy_length);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
** I'm renaming it to mystrtok() in order to avoid conflict with the
|
||||
** system which might have it
|
||||
** I also formatted to my coding style
|
||||
** 10/08/95, muquit@semcor.com
|
||||
*/
|
||||
|
||||
char *mutilsStrtok(char *s,char *delim)
|
||||
{
|
||||
register char
|
||||
*spanp;
|
||||
|
||||
register int
|
||||
c,
|
||||
sc;
|
||||
|
||||
char
|
||||
*tok;
|
||||
|
||||
static char
|
||||
*last;
|
||||
|
||||
|
||||
if (s == (char *) NULL && (s = last) == (char *) NULL)
|
||||
return ((char *) NULL);
|
||||
|
||||
/*
|
||||
** Skip (span) leading delimiters (s += strspn(s, delim), sort of).
|
||||
*/
|
||||
cont:
|
||||
c = *s++;
|
||||
for (spanp = (char *)delim; (sc = *spanp++) != 0;)
|
||||
{
|
||||
if (c == sc)
|
||||
goto cont;
|
||||
}
|
||||
|
||||
if (c == 0)
|
||||
{ /* no non-delimiter characters */
|
||||
last = (char *) NULL;
|
||||
return ((char *)NULL);
|
||||
}
|
||||
tok = s - 1;
|
||||
|
||||
/*
|
||||
* Scan token (scan for delimiters: s += strcspn(s, delim), sort of).
|
||||
* Note that delim must have one NUL; we stop if we see that, too.
|
||||
*/
|
||||
for (;;)
|
||||
{
|
||||
c = *s++;
|
||||
spanp = (char *)delim;
|
||||
do
|
||||
{
|
||||
if ((sc = *spanp++) == c)
|
||||
{
|
||||
if (c == 0)
|
||||
s = (char *) NULL;
|
||||
else
|
||||
s[-1] = '\0';
|
||||
last = s;
|
||||
return (tok);
|
||||
}
|
||||
} while (sc != 0);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** convert a string to upper case
|
||||
** borrowed from C snippets library (strupr.c)
|
||||
*/
|
||||
char *mutilsStrUpper(char *str)
|
||||
{
|
||||
char
|
||||
*s;
|
||||
|
||||
if (str)
|
||||
{
|
||||
for (s=str; *s; ++s)
|
||||
*s=toupper(*s);
|
||||
}
|
||||
|
||||
return (str);
|
||||
}
|
||||
|
||||
/*
|
||||
** convert a string to lower case
|
||||
** borrowed from C snippets library (strupr.c)
|
||||
*/
|
||||
char *mutilsStrLower(char *str)
|
||||
{
|
||||
char
|
||||
*s;
|
||||
|
||||
if (str)
|
||||
{
|
||||
for (s=str; *s; ++s)
|
||||
*s=tolower(*s);
|
||||
}
|
||||
|
||||
return (s);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#include "mutils.h"
|
||||
|
||||
int main (int argc,char **argv)
|
||||
{
|
||||
int
|
||||
rc;
|
||||
if (argc != 3)
|
||||
{
|
||||
(void) fprintf(stderr," usage: %s <string> <mask>\n",argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
rc=mutilsIsinname(argv[1],argv[2]);
|
||||
if (rc)
|
||||
(void) fprintf(stderr,"%s %s fits\n",argv[1],argv[2]);
|
||||
return(0);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
#include "mutils.h"
|
||||
|
||||
int main(int argc,char **argv)
|
||||
{
|
||||
char
|
||||
buf[BUFSIZ];
|
||||
|
||||
FILE
|
||||
*ifp,
|
||||
*ofp;
|
||||
|
||||
if (argc != 2)
|
||||
{
|
||||
(void) fprintf(stderr,"usage: %s file\n",argv[0]);
|
||||
return (1);
|
||||
}
|
||||
|
||||
(void) sprintf(buf,"%s.b64",argv[1]);
|
||||
ifp=fopen(argv[1],"r");
|
||||
if (ifp == NULL)
|
||||
{
|
||||
(void) fprintf(stderr,"could not open for reading: %s\n",argv[1]);
|
||||
return (1);
|
||||
}
|
||||
|
||||
ofp=fopen(buf,"w");
|
||||
if (ofp == NULL)
|
||||
{
|
||||
(void) fprintf(stderr,"could not open for writing: %s\n",buf);
|
||||
return (1);
|
||||
}
|
||||
|
||||
mutilsBase64Encode(ifp,ofp);
|
||||
|
||||
(void) fclose(ifp);
|
||||
(void) fclose(ofp);
|
||||
|
||||
|
||||
return (0);
|
||||
}
|
||||
Reference in New Issue
Block a user