3232/* A simple implementation of some important "string.h" functions */
3333#ifdef ARG_STANDALONE
3434# define ARG_ASSERT (x )
35- # define ARG_STRCMP (a , b ) arg_strcmp(a, b)
3635# define ARG_STRLEN (str ) arg_strlen(str)
3736# define ARG_STRCPY (dest , src ) arg_strcpy(dest, src)
3837# define ARG_MEMCPY (dest , src , n ) arg_memcpy(dest, src, n)
@@ -59,28 +58,11 @@ static void * arg_memcpy (void * dest, void * src, size_t n) {
5958 return dest ;
6059}
6160
62- /* A slightly altered strcmp(), will return 0 even if the strings
63- * don't match after the first one ended (i.e: abc = abcde, but
64- * abc != abdc)
65- * IN char * f: first string
66- * IN char * f: second string
67- *
68- * RETURN int:
69- * non-zero, if the strings don't match */
70- static int arg_strcmp (char * f , char * s ) {
71- while (* f && * s ) {
72- if (!(* f == * s ))
73- break ;
74- ++ f ; ++ s ;
75- }
76- return * (unsigned char * )f - * (unsigned char * )s ;
77- }
7861
7962#else
8063# include <string.h>
8164# include <assert.h>
8265# define ARG_ASSERT (x ) assert(x)
83- # define ARG_STRCMP (a , b ) strcmp(a, b)
8466# define ARG_STRLEN (str ) strlen(str)
8567# define ARG_STRCPY (dest , src ) strcpy(dest, src)
8668# define ARG_MEMCPY (dest , src , n ) memcpy(dest, src, n)
@@ -111,7 +93,30 @@ static int arg_strcmp (char * f, char * s) {
11193# define ARG_SUCCESS 1
11294#endif
11395
114- #define ARG_STREQ (a , b ) (ARG_STRCMP(a, b) == 0)
96+ #define ARG_STREQ (a , b ) (arg_strcmp(a, b) == 0)
97+
98+ /* A slightly altered strcmp(), will return 0 even if the strings
99+ * don't match after the first one ended (i.e: abc = abcde, but
100+ * abc != abdc)
101+ * IN char * f: first string
102+ * IN char * f: second string
103+ *
104+ * RETURN int:
105+ * non-zero, if the strings don't match */
106+ static int arg_strcmp (char * f , char * * s ) {
107+ char * rest_ptr = * s ;
108+ while (* f && * * s ) {
109+ if (!(* f == * * s )) {
110+ break ;
111+ }
112+ ++ f ; ++ (* s );
113+ }
114+ int diff ;
115+ if ((diff = * (unsigned char * )f - * (unsigned char * )* s ) != 0 )
116+ * s = rest_ptr ;
117+
118+ return diff ;
119+ }
115120
116121typedef int arg_callback ();
117122typedef int p_arg_handler (void * data_ptr , size_t blksize , void * retval );
0 commit comments