- Files:
-
- /trunk/includes/string.h (modified) (1 diff)
- /trunk/includes/stdio.h (modified) (2 diffs)
- /trunk/personality.txt (modified) (1 diff)
- /trunk/functions/stdio/ferror.c (modified) (1 diff)
- /trunk/functions/stdio/feof.c (modified) (1 diff)
- /trunk/functions/stdio/clearerr.c (modified) (1 diff)
- /trunk/functions/string/strcat.c (modified) (1 diff)
- /trunk/functions/string/strstr.c (modified) (1 diff)
- /trunk/functions/string/strncpy.c (modified) (1 diff)
- /trunk/functions/string/strxfrm.c (modified) (1 diff)
- /trunk/functions/string/memmove.c (modified) (1 diff)
- /trunk/functions/string/strchr.c (modified) (1 diff)
- /trunk/functions/string/strlen.c (modified) (1 diff)
- /trunk/functions/string/strcmp.c (modified) (1 diff)
- /trunk/functions/string/memchr.c (modified) (1 diff)
- /trunk/functions/string/memcmp.c (modified) (1 diff)
- /trunk/functions/string/strncat.c (modified) (1 diff)
- /trunk/functions/string/strcoll.c (modified) (1 diff)
- /trunk/functions/string/strerror.c (modified) (1 diff)
- /trunk/functions/string/strcpy.c (modified) (1 diff)
- /trunk/functions/string/strncmp.c (modified) (1 diff)
- /trunk/functions/string/strpbrk.c (modified) (1 diff)
- /trunk/functions/string/strrchr.c (modified) (1 diff)
- /trunk/functions/string/strspn.c (modified) (1 diff)
- /trunk/functions/string/memset.c (modified) (1 diff)
- /trunk/functions/string/memcpy.c (modified) (1 diff)
- /trunk/functions/string/strcspn.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
/trunk/includes/string.h
r17 r27 203 203 204 204 /** STRing SPaN. Compares two C strings, determining the length of the 205 * substring where both strings are equal.205 * substring containing only characters from the second string. 206 206 * @param src_1 The first string to be compared. 207 207 * @param src_2 The second string to be compared. /trunk/includes/stdio.h
r14 r29 11 11 #define __STDIO_H __STDIO_H 12 12 13 // TODO: Documentation, checking macros for personality14 15 13 // ---------------------------------------------------------------------------- 16 14 // MACROS 17 15 16 // personality: FILENAME_MAX, FOPEN_MAX, L_tmpnam, TMP_MAX, stderr, stdin, 17 // stdout 18 18 19 #include "__NULL.h" 19 20 20 #define _IOFBF // TODO 21 #define _IOLBF // TODO 22 #define _IONBF // TODO 23 #define BUFSIZ // TODO 24 #define EOF // TODO 25 #define FILENAME_MAX // TODO 26 #define FOPEN_MAX // TODO 27 #define L_tmpnam // TODO 28 #define SEEK_CUR // TODO 29 #define SEEK_END // TODO 30 #define SEEK_SET // TODO 31 #define TMP_MAX // TODO 32 33 #define stderr // TODO 34 #define stdin // TODO 35 #define stdout // TODO 21 #define _IOFBF 0 // @see setvbuf() 22 #define _IOLBF 1 // @see setvbuf() 23 #define _IONBF 2 // @see setvbuf() 24 25 #define SEEK_SET 0 // @see fseek() 26 #define SEEK_CUR 1 // @see fseek() 27 #define SEEK_END 2 // @see fseek() 28 29 #define EOF -1 36 30 37 31 // ---------------------------------------------------------------------------- … … 40 34 #include "__size_t.h" 41 35 42 typedef FILE; // TODO - personality? 43 typedef fpos_t; // TODO - personality? 44 typedef size_t; // TODO - personality? 36 typedef FILE; // object holding all stream information, including file pos, 37 // buffer (optional), error indicator, EOF indicator 38 typedef fpos_t; // position indicator type, other than array - personality? 39 // (see mbstate_t) 45 40 46 41 // ---------------------------------------------------------------------------- 47 42 // FUNCTIONS 48 43 49 // TODO: Documentation. 50 51 void clearerr( FILE * stream ); 52 int fclose( FILE * stream ); 44 /* TABLE OF CONTENTS (in order of appearance) 45 * 46 * General File Handling 47 * * fopen() 48 * * freopen() 49 * * fflush() 50 * * feof() 51 * * ferror() 52 * * clearerr() 53 * * fclose() 54 * 55 * Rename / Remove 56 * * rename() 57 * * remove() 58 * 59 * Temporary Files 60 * * tmpfile() 61 * * tmpnam() 62 * 63 * File Positioning 64 * * fseek() 65 * * rewind() 66 * * ftell() 67 * * fgetpos() 68 * * fsetpos() 69 * 70 * Reading 71 * * fgetc() 72 * * getc() 73 * * getchar() 74 * * ungetc() 75 * * fgets() 76 * * gets() 77 * 78 * Writing 79 * * fputc() 80 * * putc() 81 * * putchar() 82 * * fputs() 83 * * puts() 84 * 85 * Formatted Reading 86 * * fscanf() 87 * * scanf() 88 * * sscanf() 89 * * vfscanf() 90 * * vscanf() 91 * * vsscanf() 92 * 93 * Formatted Writing 94 * * fprintf() 95 * * printf() 96 * * sprintf() 97 * * snprintf() 98 * * vfprintf() 99 * * vprintf() 100 * * vsprintf() 101 * * vsnprintf() 102 * 103 * Special 104 * * perror() 105 * 106 * Binary Read / Write 107 * * fread() 108 * * fwrite() 109 * 110 * Buffer Handling 111 * * setvbuf() 112 * * setbuf() 113 * 114 */ 115 116 /** File OPEN. Opens the file specified by the given name. 117 @param filename Name of the file to be opened. 118 @param mode One of r, w, a, rb, wb, ab, r+, w+, a+, rb+, wb+, ab+, 119 specifying which mode to open the file in. 120 @return A file handle associated with the opened file, NULL if failed. 121 */ 122 FILE * fopen( const char * restrict filename, const char * restrict mode ); 123 124 /** File REOPEN. Opens the file specified by the given name, associating it 125 with the given file handle. If filename is NULL, it is attempted to change 126 the mode of the already opened file associated with the given file handle. 127 (This function can e.g. be used to reassociate stdin / stdout / stderr with 128 a filename.) 129 @param filename Name of the file to be opened. 130 @param mode One of r, w, a, rb, wb, ab, r+, w+, a+, rb+, wb+, ab+, 131 specifying which mode to open the file in. 132 @param fh The file handle to associate with the opened file. 133 @return fh if successful, NULL if failed. 134 */ 135 FILE * freopen( const char * restrict filename, const char * restrict mode, FILE * fh ); 136 137 /** File FLUSH. Flushes output buffers (if any) for given file handle. If 138 parameter is NULL, flushes output buffers for all file handles. 139 @param fh The file handle. 140 @return 0 if successful, EOF if failed (setting error indicators). 141 */ 142 int fflush( FILE * fh ); 143 144 /** File EOF. Tests whether EOF is set for a given file. 145 @param fh The file handle. 146 @return 0 if EOF is not set, non-zero if EOF is set. 147 */ 53 148 int feof( FILE * stream ); 149 150 /** File ERROR. Tests whether error indicators are set for a given file. 151 @param fh The file handle. 152 @return 0 if no error indicators are set, non-zero otherwise. 153 */ 54 154 int ferror( FILE * stream ); 55 int fflush( FILE * stream ); 56 FILE * fopen( const char * restrict filename, const char * restrict mode ); 57 FILE * freopen( const char * restrict filename, const char * restrict mode, FILE * stream ); 155 156 /** CLEAR ERRor. Clears EOF and error indicator of a FILE handle. 157 @param fh The file handle. 158 */ 159 void clearerr( FILE * fh ); 160 161 /** File CLOSE. Flush output buffers (if any) and closes the FILE handle. 162 @param stream The file handle. 163 @return 0 if successful, non-zero if failed. (In any case, the FILE handle 164 is invalid afterwards.) 165 */ 166 int fclose( FILE * fh ); 167 168 // ---------------------------------------------------------------------------- 169 170 /** RENAME file. Causes a file to be no longer accessible under a given name, 171 but a new name instead. If a file with the intended new name already 172 exists, this implementation of rename() fails, returning INT_MAX. 173 @param old Name of the file to be renamed. 174 @param new Name to rename the file to. 175 @return 0 if successful, non-zero if failed. (Implementation defined: 176 INT_MAX if target file name already exists.) 177 */ 178 int rename( const char * old, const char * new ); 179 180 /** REMOVE file. Causes a file to be no longer accessible under a given name. 181 If the file is currently open, this implementation of remove() fails, 182 returning INT_MAX. 183 @param filename Name of the file to be removed. 184 @return 0 if successful, non-zero if failed. (Implementation defined: 185 INT_MAX if the file is currently open.) 186 */ 58 187 int remove( const char * filename ); 59 int rename( const char * old, const char * new ); 188 189 // ---------------------------------------------------------------------------- 190 191 /** TeMPorary FILE. Opens a file in "wb+" mode that will be automatically 192 deleted when closed, or when the program terminates. 193 @return A file handle for the temporary file. (NULL if opening failed.) 194 */ 195 FILE * tmpfile( void ) 196 197 /** TeMPorary NAMe. Generates a random file name that does not yet exist in the 198 file system. Note that a file generated with this name is not "temporary", 199 and must be remove()d normally. 200 @param dest NULL, or a char[ L_tmpnam ] array. 201 @return A pointer to a static internal buffer containing the file name, 202 or NULL if no file name could be generated. If 'dest' is not NULL, 203 writes the file name to and returns 'dest'. 204 */ 205 char * tmpnam( char * dest ); 206 207 // ---------------------------------------------------------------------------- 208 209 /** File SEEK. Sets the current position in a file to the values specified by 210 start and offset. 211 @param fh The file handle. 212 @param offset The offset from 'start' to position to. 213 @param start The starting point from which to calculate the offset. May be 214 one of SEEK_SET, SEEK_CUR, SEEK_END. 215 @return 0 if successful, non-zero if error encountered. 216 */ 217 int fseek( FILE * fh, long offset, int start ); 218 219 /** REWIND file. Equivalent to (void) fseek( fh, 0, SEEK_SET ). 220 @param fh The file handle. 221 */ 60 222 void rewind( FILE * stream ); 61 void setbuf( FILE * restrict stream, char * restrict buf ); 62 int setvbuf( FILE * restrict stream, char * restrict buf, int mode, size_t size ); 63 FILE * tmpfile( void ) 64 char * tmpnam( char * s ); 65 66 int fseek( FILE * stream, long offset, int mode ); 223 224 /** File TELL position. Tells the current offset into a given file. 225 @param fh The file handle. 226 @return The offset into the file. 227 */ 228 long ftell( FILE * fh ); 229 230 /** File GET POSition. Stores the current state and position in a file. 231 @param fh The file handle. 232 @param pos The object to store the current state in. 233 @return 0 if successful, non-zero if error encountered. 234 */ 235 int fgetpos( FILE * restrict fh, fpos_t * restrict pos ); 236 237 /** File SET POSition. Sets the current file position to the value stored in a 238 given fpos_t object. 239 @param fh The file handle. 240 @param pos The fpos_t object. 241 @return 0 if successful, non-zero if error encountered. 242 */ 67 243 int fsetpos( FILE * stream, const fpos_t * pos ); 68 int fgetpos( FILE * restrict stream, fpos_t * restrict pos ); 69 long ftell( FILE * stream ); 70 71 int fgetc( FILE * stream ); 72 char *fgets( char * restrict s, int n, FILE * restrict stream ); 73 size_t fread( void * restrict ptr, size_t size, size_t nelem, FILE * restrict stream ); 74 int getc( FILE * stream ); 244 245 // ---------------------------------------------------------------------------- 246 247 /** File GET Character. Reads a character from file. 248 @param fh The file handle. 249 @return The next character in the file, as unsigned char converted to int, 250 or EOF if end of file is reached. 251 */ 252 int fgetc( FILE * fh ); 253 254 /** GET Character. Equivalent to fgetc(), but may be implemented as macro, and 255 is allowed to evaluate its parameter more than once. 256 @param fh The file handle. 257 @return The character read, or EOF if end of file / error encountered. 258 */ 259 int getc( FILE * fh ); 260 261 /** GET CHARacter. Equivalent to getc( stdin ). 262 @return The character read, or EOF if end of file / error encountered. 263 */ 75 264 int getchar( void ); 76 char * gets( char * s ); 77 int ungetc( int c, FILE * stream ); 78 265 266 /** UN-GET Character. Puts a character back into an input stream. 267 @param c The character to put back. 268 @param fh The file handle. 269 @return The character put back, EOF if error encountered. 270 */ 271 int ungetc( int c, FILE * fh ); 272 273 /** File GET String. Reads a line (terminated by newline character) from file, 274 but reading no more than n characters. 275 @param dest The char array to write into. 276 @param n The maximum number of characters to read. 277 @param fh The file handle. 278 @return 'dest', or NULL if an error occurred. 279 */ 280 char * fgets( char * restrict dest, int n, FILE * restrict fh ); 281 282 /** GET String. Equivalent to fgets( dest, stdin ). 283 @param dest The character array to write to. 284 @return 'dest', or NULL if an error occurred. 285 */ 286 char * gets( char * dest ); 287 288 // ---------------------------------------------------------------------------- 289 290 /** File PUT Character. Writes a character to file. 291 @param c The character (when converted to unsigned char) to write. 292 @param fh The file handle. 293 @return 'c', or EOF if an error occurred. 294 */ 79 295 int fputc( int c, FILE * stream ); 296 297 /** PUT Character. Equivalent to fputc( c, stdout ), but may be implemented as 298 a macro, and may evaluate the file handle more than once. 299 @param c The character to write. 300 @param fh The file handle. 301 @return The character written, or EOF if error encountered. 302 */ 303 int putc( int c, FILE * fh ); 304 305 /** PUT CHARacter. Equivalent to putc( c, stdout ). 306 @param c The character to write. 307 @return The character written, or EOF if error encountered. 308 */ 309 int putchar( int c ); 310 311 /** File PUT String. Writes a C string to file. 312 @param src The string to write. 313 @param fh The file handle. 314 @return >= 0 if successful, or EOF if an error occurred. 315 */ 80 316 int fputs( const char * restrict s, FILE * restrict stream ); 81 size_t fwrite( const void * restrict ptr, size_t size, size_t nelem, FILE * restrict stream ); 82 void perror( const char * s ); 83 int putc( int c, FILE * stream ); 84 int putchar( int c ); 85 int puts( const char * s ); 86 87 int fscanf( FILE * restrict stream, const char * restrict format, ... ); 317 318 /** PUT String. Write a C string to stdout. 319 @param src The C string to write. 320 @return >= 0 if successful, EOF if error encountered. 321 */ 322 int puts( const char * src ); 323 324 // ---------------------------------------------------------------------------- 325 326 /** File SCAN Formatted. Reads from given file handle, under control of a 327 formatting string, the values of variables pointed to by 0..n pointers. 328 @param fh The file handle. 329 @param format The formatting string. 330 @param ... A list of 0..n pointers corresponding to placeholders in 331 'format'. 332 @return EOF if failed, number of values successfully assigned otherwise. 333 */ 334 int fscanf( FILE * restrict fh, const char * restrict format, ... ); 335 336 /** SCAN Formatted. Equivalent to fscanf( stdin, format, ... ) 337 @param format The formatting string. 338 @param ... A list of 0..n pointers corresponding to placeholders in 339 'format'. 340 @return EOF if failed, number of values successfully assigned otherwise. 341 */ 88 342 int scanf( const char * restrict format, ... ); 89 int sscanf( const char * restrict s, const char * restrict format, ... ); 90 int vfscanf( FILE * restrict stream, const char * restrict format, va_list ap ); 91 int vscanf( const char * restrict format, va_list ap ); 92 int vsscanf( const char * restrict s, const char * restrict format, va_list ap ); 93 343 344 /** String SCAN Formatted. Equivalent to scanf( format, ... ), but using a C 345 string instead of a file handle for input. 346 @param src The input string. 347 @param format The formatting string. 348 @param ... A list of 0..n pointers corresponding to placeholders in 349 'format'. 350 @return EOF if failed, number of values successfully assigned otherwise. 351 */ 352 int sscanf( const char * restrict src, const char * restrict format, ... ); 353 354 /** Variable File SCAN Formatted. Equivalent to fscanf( fh, format, ... ), 355 with the variable-length parameter list replaced by a va_list, created by 356 the va_start macro. 357 @param fh The file handle. 358 @param format The formatting string. 359 @param args The argument list created by the va_start macro. 360 @return Number of characters printed. 361 */ 362 int vfscanf( FILE * restrict stream, const char * restrict format, va_list args ); 363 364 /** Variable SCAN Formatted. Equivalent to vfscanf( stdin, format, args ). 365 @param format The formatting string. 366 @param args The argument list created by the va_start macro. 367 @return Number of characters printed. 368 */ 369 int vscanf( const char * restrict format, va_list args ); 370 371 /** Variable String SCAN Formatted. Equivalent to vscanf( format, args ), but 372 reading from a C string instead of stdin. 373 @param src The C string to read from. 374 @param format The formatting string. 375 @param args The argument list created by the va_start macro. 376 @return Number of characters printed. 377 */ 378 int vsscanf( const char * restrict src, const char * restrict format, va_list ap ); 379 380 // ---------------------------------------------------------------------------- 381 382 /** File PRINT Formatted. Prints to given file handle, under control of a 383 formatting string, the values of 0..n variables. 384 @param fh The file handle. 385 @param format The formatting string. 386 @param ... A list of 0..n variables corresponding to placeholders in 387 'format'. 388 @return Number of characters printed, negative value if error occurred. 389 */ 94 390 int fprintf( FILE * restrict stream, const char * restrict format, ... ); 391 392 /** PRINT Formatted. Equivalent to fprintf( stdout, format, ... ). 393 @param format The formatting string. 394 @param ... A list of 0..n variables corresponding to placeholders in 395 'format'. 396 @return Number of characters printed. 397 */ 95 398 int printf( const char * restrict format, ... ); 399 400 /** String PRINT Formatted. Equivalent to printf( format, ... ), but writing 401 to a char array instead of stdout. 402 @param dest The char array to write to. 403 @param format The formatting string. 404 @param ... A list of 0..n variables corresponding to placeholders in 405 'format'. 406 @return Number of characters printed. 407 */ 408 int sprintf( char * restrict dest, const char * restrict format, ... ); 409 410 /** String N PRINT Formatted. Equivalent to sprintf( dest, format, ... ), but 411 will not write more than n characters. 412 @param dest The char array to write to. 413 @param n The maximum number of characters to write. 414 @param format The formatting string. 415 @param ... A list of 0..n variables corresponding to placeholders in 416 'format'. 417 @return Number of characters printed. 418 */ 96 419 int snprintf( char * restrict s, size_t n, const char * restrict format, ... ); 97 int sprintf( char * restrict s, const char * restrict format, ... ); 98 int vfprintf( FILE * restrict stream, const char * restrict format, va_list ap ); 99 int vprintf( const char * restrict format, va_list ap ); 100 int vsnprintf( char * restrict s, size_t n, const char * restrict format, va_list ap ); 420 421 /** Variable File PRINT Formatted. Equivalent to fprintf( fh, format, ... ), 422 with the variable-length parameter list replaced by a va_list, created by 423 the va_start macro. 424 @param fh The file handle. 425 @param format The formatting string. 426 @param args The argument list created by the va_start macro. 427 @return Number of characters printed. 428 */ 429 int vfprintf( FILE * restrict fh, const char * restrict format, va_list args ); 430 431 /** Variable PRINT Formatted. Equivalent to vfprintf( stdout, format, args ). 432 @param format The formatting string. 433 @param args The argument list created by the va_start macro. 434 @return Number of characters printed. 435 */ 436 int vprintf( const char * restrict format, va_list args ); 437 438 /** Variable String PRINT Formatted. Equivalent to vprintf( format, args ), but 439 writing to a char array instead to stdout. 440 @param dest The char array to write to. 441 @param format The formatting string. 442 @param args The argument list created by the va_start macro. 443 @return Number of characters printed. 444 */ 101 445 int vsprintf( char * restrict s, const char * restrict format, va_list ap); 446 447 /** Variable String N PRINT Formatted. Equivalent to vsprintf( dest, format, 448 args ), but will not write more than n characters. 449 @param dest The char array to write to. 450 @param n Maximum number of characters to write. 451 @param format The formatting string. 452 @param args The argument list created by the va_start macro. 453 @return Number of characters printed. 454 */ 455 int vsnprintf( char * restrict dest, size_t n, const char * restrict format, va_list ap ); 456 457 // ---------------------------------------------------------------------------- 458 459 /** Print ERROR. 460 Equivalent to fprintf( stderr, "%s: %s\n", text, strerror( errno ) ). 461 @param test Text to prepend the error message with. 462 */ 463 void perror( const char * text ); 464 465 // ---------------------------------------------------------------------------- 466 467 /** File READ. Reads a number of objects of a given size from file, and into 468 a memory area. 469 @param dest The memory area to write into. 470 @param size The size of one object. 471 @param n The number of objects to read. 472 @param fh The file handle. 473 @return The number of objects successfully read. 474 */ 475 size_t fread( void * restrict dest, size_t size, size_t n, FILE * restrict fh ); 476 477 /** File WRITE. Writes a number of objects from a memory area to file. 478 @param src The memory area to write from. 479 @param size The size of a single object. 480 @param n The number of objects to write. 481 @param fh The file handle. 482 @return The number of objects successfully written. 483 */ 484 size_t fwrite( const void * restrict src, size_t size, size_t n, FILE * restrict fh ); 485 486 // ---------------------------------------------------------------------------- 487 488 /** SET Virtual BUFfer. Sets buffering mode and (optionally) the memory used 489 for buffering, for a given file handle. 490 This function must only be called immediately after associating the file 491 handle with a file, before any operations are called on the file handle. 492 @param fh The file handle. 493 @param buf A pointer to the memory area to use for buffering, or NULL to 494 use internally assigned buffer memory. 495 @param mode One of _IOFBF, _IOLBF, _IONBF. 496 @param size Size of the memory area to be used for buffering. 497 */ 498 int setvbuf( FILE * restrict fh, char * restrict buf, int mode, size_t size ); 499 500 /** SET BUFfer. Equivalent to (void) setvbuf( fh, buf, _IOFBF, BUFSIZ ), or 501 (void) setvbuf( fh, NULL, _IONBF, BUFSIZ ) if buf == NULL. 502 @param fh The file handle to be passed to setvbuf(). 503 @param buf The buffer pointer to be passed to setvbuf(). 504 */ 505 void setbuf( FILE * restrict fh, char * restrict buf ); 506 507 // ---------------------------------------------------------------------------- 102 508 103 509 /* PDPC code - unreviewed /trunk/personality.txt
r13 r26 1 {\pwd2\ansi{\*\pwdcomment 1 // ---------------------------------------------------------------------------- 2 // $Id$ 3 // ---------------------------------------------------------------------------- 4 // Public Domain C Library - http://pdclib.sourceforge.net 5 // This code is Public Domain. Use, modify, and redistribute at will. 6 // ---------------------------------------------------------------------------- 7 // Description of the personality concept 8 // ---------------------------------------------------------------------------- 2 9 3 ************************************************************************ 4 * 5 * Dies ist ein Microsoft Pocket Word-Dokument. 6 * 7 * Um dieses Pocket Word-Dokument in Microsoft Word anzuzeigen, brauchen 8 * Sie den Pocket Word-Konverter für Microsoft Office. Weitere Informationen 9 * finden Sie in der Microsoft Windows CE-Website: 10 * 11 * http://www.microsoft.com/mobile/hpc\r 12 * 13 ************************************************************************ 10 The pdclib is aimed at providing a fully conforming implementation of the C99 11 standard library, with a focus on adaptability to diverse environments. 14 12 15 }\ansicpg1252\deff0\deflang1031{\fonttbl{\f0\fmodern\fprq1\fcharset0 Courier New;}} 16 {\colortbl ;\red0\green0\blue255;} 17 \viewkind4\uc1\pard\f0\fs18 // ----------------------------------------------------------------------------\par 18 // $Id$\par 19 // ----------------------------------------------------------------------------\par 20 // Public Domain C Library - \cf1\ul http://pdclib.sourceforge.net\cf0\ul0\par 21 // This code is Public Domain. Use, modify, and redistribute at will.\par 22 // ----------------------------------------------------------------------------\par 23 // Description of the personality concept\par 24 // ----------------------------------------------------------------------------\par 25 \par 26 The pdclib is aimed at providing a fully conforming implementation of the C99\par 27 standard library, with a focus on adaptability to diverse environments.\par 28 \par 29 That means, an effort was made to make this library useful to you, no matter if\par 30 you are looking for a replacement for the CLib provided by your system vendor,\par 31 for a basic CLib to develop your own operating system on / with, or for a "bare\par 32 bones" CLib to test your software against a strict "standard only" library.\par 33 \par 34 The traditional way of providing this kind of cross-platform support is the\par 35 preprocessor directive '#ifdef'. However, careless use of this feature can make\par 36 source code next to intelligible and hard to maintain. Hence, an effort was\par 37 made to encapsule such platform dependencies, by the concept of "personality\par 38 modules".\par 39 \par 40 A personality module consists of three parts: drop-ins, glue code, and the\par 41 header file "__personality.h", in an appropriately named subdirectory of\par 42 pdclib/personalities.\par 43 \par 44 // ----------------------------------------------------------------------------\par 45 // DROP-INS\par 46 \par 47 The standard includes limits.h and stdint.h define various intrinsics of the\par 48 integer types of a platform. The standard include float.h does the same for the\par 49 floating point types. Throughout pdclib, these defines have been put to maximum\par 50 use.\par 51 \par 52 Each personality module must provide those three include files, so that pdclib\par 53 "knows" about the data type intrinsics of the platform in question. The files\par 54 are simply "dropped" into the pdclib/includes subdirectory prior to building\par 55 pdclib.\par 56 \par 57 // ----------------------------------------------------------------------------\par 58 // GLUE CODE \par 59 \par 60 Most functions of pdclib could be implemented generically - i.e., any supported\par 61 platform uses identical source code for them. Some functions, however, interact\par 62 closely with the operating system at one point or another. pdclib implements\par 63 the "top half" of those functions, where possible. The "bottom half" has to be\par 64 provided by the operating system.\par 65 \par 66 If pdclib is used on a host OS, as replacement for a vendor-supplied CLib, the\par 67 personality module should contain the "glue code" necessary to match the OS\par 68 provided services to pdclib's top/bottom interface (see below).\par 69 \par 70 When a new operating system uses pdclib as "native" C standard library, the\par 71 documentation of the top/bottom interfaces (see below) should help in bringing\par 72 OS and pdclib together. In this case, no dedicated "glue code" is necessary.\par 73 \par 74 // ----------------------------------------------------------------------------\par 75 // __PERSONALITY.H\par 76 \par 77 At some points within the library, information about the environment is needed\par 78 which cannot be derived from the drop-ins. In those places, "__personality.h"\par 79 is included; this file defines a couple of symbols specifying those environment\par 80 options for the personality module. A template for __personality.h can be found\par 81 in the pdclib/personalities directory.\par 82 \par 83 The symbols defined in personality.h are all named __PERSONALITY_*, with "*"\par 84 being replaced with a service or feature provded or not provided. Never is the\par 85 name of an OS, compiler, or hardware used in such symbols - later generations\par 86 of either might provide a service that older ones did not, and it is also more\par 87 self-explanatory if the symbol reads "__PERSONALITY_SUPPORTS_XYZ" instead of\par 88 "__PERSONALITY_MyOS", which basically leaves the reader clueless as to what\par 89 makes MyOS special in this case - information that might be outdated already\par 90 without anyone being the wiser.\par 91 \par 92 If a new, exotic personality is added that requires a new symbol to be added to personality.h, that symbol is always worded in a way that the old personality\par 93 modules need not be changed. The default goes without saying, so to speak.\par 94 \par 95 // ----------------------------------------------------------------------------\par 96 // TOP/BOTTOM INTERFACE\par 97 \par 98 What follows is a documentation of the "bottom half" functions required by\par 99 pdclib, with an exact description of interface, required functionality, etc.\par 100 \par 101 } 102 13 That means, an effort was made to make this library useful to you, no matter if 14 you are looking for a replacement for the CLib provided by your system vendor, 15 for a basic CLib to develop your own operating system on / with, or for a "bare 16 bones" CLib to test your software against a strict "standard only" library. 17 18 The traditional way of providing this kind of cross-platform support is the 19 preprocessor directive '#ifdef'. However, careless use of this feature can make 20 source code next to intelligible and hard to maintain. Hence, an effort was 21 made to encapsule such platform dependencies, by the concept of "personality 22 modules". 23 24 A personality module consists of three parts: drop-ins, glue code, and the 25 header file "__personality.h", in an appropriately named subdirectory of 26 pdclib/personalities. 27 28 // ---------------------------------------------------------------------------- 29 // DROP-INS 30 31 The standard includes limits.h and stdint.h define various intrinsics of the 32 integer types of a platform. The standard include float.h does the same for the 33 floating point types. Throughout pdclib, these defines have been put to maximum 34 use. 35 36 Each personality module must provide those three include files, so that pdclib 37 "knows" about the data type intrinsics of the platform in question. The files 38 are simply "dropped" into the pdclib/includes subdirectory prior to building 39 pdclib. 40 41 // ---------------------------------------------------------------------------- 42 // GLUE CODE 43 44 Most functions of pdclib could be implemented generically - i.e., any supported 45 platform uses identical source code for them. Some functions, however, interact 46 closely with the operating system at one point or another. pdclib implements 47 the "top half" of those functions, where possible. The "bottom half" has to be 48 provided by the operating system. 49 50 If pdclib is used on a host OS, as replacement for a vendor-supplied CLib, the 51 personality module should contain the "glue code" necessary to match the OS 52 provided services to pdclib's top/bottom interface (see below). 53 54 When a new operating system uses pdclib as "native" C standard library, the 55 documentation of the top/bottom interfaces (see below) should help in bringing 56 OS and pdclib together. In this case, no dedicated "glue code" is necessary. 57 58 // ---------------------------------------------------------------------------- 59 // __PERSONALITY.H 60 61 At some points within the library, information about the environment is needed 62 which cannot be derived from the drop-ins. In those places, "__personality.h" 63 is included; this file defines a couple of symbols specifying those environment 64 options for the personality module. A template for __personality.h can be found 65 in the pdclib/personalities directory. 66 67 The symbols defined in personality.h are all named __PERSONALITY_*, with "*" 68 being replaced with a service or feature provded or not provided. Never is the 69 name of an OS, compiler, or hardware used in such symbols - later generations 70 of either might provide a service that older ones did not, and it is also more 71 self-explanatory if the symbol reads "__PERSONALITY_SUPPORTS_XYZ" instead of 72 "__PERSONALITY_MyOS", which basically leaves the reader clueless as to what 73 makes MyOS special in this case - information that might be outdated already 74 without anyone being the wiser. 75 76 If a new, exotic personality is added that requires a new symbol to be added to personality.h, that symbol is always worded in a way that the old personality 77 modules need not be changed. The default goes without saying, so to speak. 78 79 // ---------------------------------------------------------------------------- 80 // TOP/BOTTOM INTERFACE 81 82 What follows is a documentation of the "bottom half" functions required by 83 pdclib, with an exact description of interface, required functionality, etc. /trunk/functions/stdio/ferror.c
r13 r30 6 6 // ---------------------------------------------------------------------------- 7 7 8 int ferror( FILE * stream ) { /* TODO */ }; 8 #ifndef __FILE_H 9 #define __FILE_H __FILE_H 10 #include <__FILE.h> 11 #endif // __FILE_H 9 12 10 /* PDPC code - unreviewed 13 int ferror( FILE * fh ) 11 14 { 12 return (stream->errorInd);15 return fh->ErrorIndicator; 13 16 } 14 *//trunk/functions/stdio/feof.c
r13 r30 6 6 // ---------------------------------------------------------------------------- 7 7 8 int feof( FILE * stream ) { /* TODO */ }; 8 #ifndef __FILE_H 9 #define __FILE_H __FILE_H 10 #include <__FILE.h> 11 #endif // __FILE_H 9 12 10 /* PDPC code - unreviewed 13 int feof( FILE * fh ) 11 14 { 12 return (stream->eofInd);15 return fh->EOFIndicator; 13 16 } 14 *//trunk/functions/stdio/clearerr.c
r13 r30 6 6 // ---------------------------------------------------------------------------- 7 7 8 void clearerr( FILE * stream ) { /* TODO */ }; 8 #ifndef __FILE_H 9 #define __FILE_H __FILE_H 10 #include <__FILE.h> 11 #endif // __FILE_H 9 12 10 /* PDPC code - unreviewed 13 void clearerr( FILE * fh ) 11 14 { 12 stream->errorInd= 0;13 stream->eofInd= 0;15 fh->ErrorIndicator = 0; 16 fh->EOFIndicator = 0; 14 17 return; 15 18 } 16 *//trunk/functions/string/strcat.c
r13 r21 6 6 // ---------------------------------------------------------------------------- 7 7 8 char * strcat( char * restrict s1, const char * restrict s2 ) { /* TODO */ }; 9 10 /* Therx code 8 char * strcat( char * restrict dest, const char * restrict src ) 11 9 { 12 while (*s1) 10 char * dest_p = dest; 11 if ( *dest_p != '\0' ) 13 12 { 14 s1++; 13 while ( *++dest_p != '\0' ) 14 { 15 // EMPTY 16 } 15 17 } 16 while ( *s1++ = *s2++)18 while ( (*dest_p++ = *src++) != '\0' ) 17 19 { 18 20 // EMPTY 19 21 } 20 return s1;22 return dest; 21 23 } 22 */23 24 /* PDPC code - unreviewed25 {26 char *p = s1;27 28 while (*p != '\0') p++;29 while ((*p = *s2) != '\0')30 {31 p++;32 s2++;33 }34 return (s1);35 }36 *//trunk/functions/string/strstr.c
r13 r25 6 6 // ---------------------------------------------------------------------------- 7 7 8 // ---------------------------------------------------------------------------- 9 // C++ 8 #include <__NULL.h> 10 9 11 const char * strstr( const char * s1, const char * s2 ) { /* TODO */ }; 12 char * strstr( char * s1, const char * s2 ) { /* TODO */ }; 13 14 // ---------------------------------------------------------------------------- 15 // Standard C 16 17 char * strstr( const char * s1, const char * s2 ) { /* TODO */ }; 18 19 /* PDPC code - unreviewed 10 char * strstr( const char * src_1, const char * src_2 ) 20 11 { 21 const char * p = s1, *p1, *p2 = s2;22 23 while ( *p)12 const char * p1 = src_1; 13 const char * p2; 14 while ( *src_1 != '\0' ) 24 15 { 25 if (*p == *s2) 16 p2 = src_2; 17 while ( ( *p2 != '\0' ) && ( *p1 == *p2 ) ) 26 18 { 27 p1 = p; 28 p2 = s2; 29 while ((*p2 != '\0') && (*p1++ == *p2++)) ; 30 if (*p2 == '\0') 31 { 32 return (char *)p; 33 } 19 ++p1; 20 ++p2; 34 21 } 35 p++; 22 if ( *p2 == '\0' ) 23 { 24 return (char *) src_1; 25 } 26 ++src_1; 27 p1 = src_1; 36 28 } 37 29 return NULL; 38 30 } 39 *//trunk/functions/string/strncpy.c
r13 r25 6 6 // ---------------------------------------------------------------------------- 7 7 8 char * strncpy( char * restrict s1, const char * restrict s2, size_t n ) { /* TODO */ }; 8 #include <__size_t.h> 9 9 10 /* PDPC code - unreviewed 11 char *strncpy(char *s1, const char *s2, size_t n) 10 char * strncpy( char * restrict dest, const char * restrict src, size_t n ) 12 11 { 13 char *p = s1; 14 size_t x; 15 16 for (x=0; x < n; x++) 12 char * tmp = dest; 13 while ( ( n-- != 0 ) && ( ( *dest++ = *src++ ) != '\0' ) ) 17 14 { 18 *p = *s2; 19 if (*s2 == '\0') break; 20 p++; 21 s2++; 15 // EMPTY 22 16 } 23 for (; x < n; x++)17 while ( n-- != 0 ) 24 18 { 25 * p++ = '\0';19 *dest++ = '\0'; 26 20 } 27 return (s1);21 return tmp; 28 22 } 29 *//trunk/functions/string/strxfrm.c
r13 r22 6 6 // ---------------------------------------------------------------------------- 7 7 8 size_t strxfrm( char * restrict s1, const char * restrict s2, size_t n ) { /* TODO */ }; 8 #include <__size_t.h> 9 9 10 /* PDPC code - unreviewed 10 // TODO: Dummy function, no locale support yet. 11 12 size_t strlen( const char * src ); 13 char * strncpy( char * restrict dest, const char * restrict src, size_t n ); 14 15 size_t strxfrm( char * restrict dest, const char * restrict src, size_t n ) 11 16 { 12 size_t oldlen; 13 14 oldlen = strlen(s2); 15 if (oldlen < n) 17 size_t len = strlen( src ); 18 if ( len < n ) 16 19 { 17 memcpy(s1, s2, oldlen); 18 s1[oldlen] = '\0'; 20 strncpy( dest, src, len ); 19 21 } 20 return (oldlen);22 return len; 21 23 } 22 *//trunk/functions/string/memmove.c
r20 r22 6 6 // ---------------------------------------------------------------------------- 7 7 8 #include < string.h>8 #include <__size_t.h> 9 9 10 10 void * memmove( void * dest, const void * src, size_t n ) /trunk/functions/string/strchr.c
r13 r23 6 6 // ---------------------------------------------------------------------------- 7 7 8 // ---------------------------------------------------------------------------- 9 // C++ 8 #include <__NULL.h> 10 9 11 const char * strchr( const char * s, int c ) { /* TODO */ }; 12 char * strchr( char * s, int c ) { /* TODO */ }; 13 14 // ---------------------------------------------------------------------------- 15 // Standard C 16 17 char * strchr( const char * s, int c ) { /* TODO */ }; 18 19 /* PDPC code - unreviewed 10 char * strchr( const char * src, int c ) 20 11 { 21 while ( *s != '\0')12 while ( *src != '\0' ) 22 13 { 23 if (*s == (char)c) return ((char *)s); 24 s++; 14 if ( *src == (const char) c ) 15 { 16 return (char *) src; 17 } 18 ++src; 25 19 } 26 return (NULL);20 return NULL; 27 21 } 28 *//trunk/functions/string/strlen.c
r13 r25 6 6 // ---------------------------------------------------------------------------- 7 7 8 size_t strlen( const char * s ) { /* TODO */ }; 8 #include <__size_t.h> 9 9 10 /* Therx code 10 size_t strlen( const char * src ) 11 11 { 12 const char * start = s1;13 while ( *s1)12 size_t len = 0; 13 while ( src[len] != '\0' ) 14 14 { 15 s1++;15 ++len; 16 16 } 17 return s1 - start;17 return len; 18 18 } 19 */20 21 /* PDPC code - unreviewed22 {23 const char *p;24 25 p = s;26 while (*p != '\0') p++;27 return ((size_t)(p - s));28 }29 *//trunk/functions/string/strcmp.c
r13 r24 6 6 // ---------------------------------------------------------------------------- 7 7 8 int strcmp( const char * s1, const char * s2 ) { /* TODO */ }; 9 10 /* Therx code 8 int strcmp( const char * src_1, const char * src_2 ) 11 9 { 12 while ( (*s1 != '\0') && (*s1 == *s2))10 while ( ( *src_1 != '\0' ) && ( *src_1 == *src_2 ) ) 13 11 { 14 s1++;15 s2++;12 ++src_1; 13 ++src_2; 16 14 } 17 return ( *(unsigned char *) s1) - (*(unsigned char *) s2);15 return ( *src_1 - *src_2 ); 18 16 } 19 */20 21 /* PDPC code - unreviewed22 {23 const unsigned char *p1;24 const unsigned char *p2;25 26 p1 = (const unsigned char *)s1;27 p2 = (const unsigned char *)s2;28 while (*p1 != '\0')29 {30 if (*p1 < *p2) return (-1);31 else if (*p1 > *p2) return (1);32 p1++;33 p2++;34 }35 if (*p2 == '\0') return (0);36 else return (-1);37 }38 *//trunk/functions/string/memchr.c
r19 r22 6 6 // ---------------------------------------------------------------------------- 7 7 8 #include <string.h> 8 #include <__size_t.h> 9 #include <__NULL.h> 9 10 10 11 void * memchr( const void * src, int c, size_t n ) /trunk/functions/string/memcmp.c
r19 r22 6 6 // ---------------------------------------------------------------------------- 7 7 8 #include < string.h>8 #include <__size_t.h> 9 9 10 10 int memcmp( const void * src_1, const void * src_2, size_t n ) /trunk/functions/string/strncat.c
r13 r25 6 6 // ---------------------------------------------------------------------------- 7 7 8 char * strncat( char * restrict s1, const char * restrict s2, size_t n ) { /* TODO */ }; 8 #include <__size_t.h> 9 9 10 /* PDPC code - unreviewed 10 char * strncat( char * restrict dest, const char * restrict src, size_t n ) 11 11 { 12 char *p = s1; 13 size_t x = 0; 14 15 while (*p != '\0') p++; 16 while ((*s2 != '\0') && (x < n)) 12 char * tmp = dest; 13 while ( *dest != '\0' ) 17 14 { 18 *p = *s2; 19 p++; 20 s2++; 21 x++; 15 ++dest; 22 16 } 23 *p = '\0'; 24 return (s1); 17 while ( ( n-- > 0 ) && ( *src != '\0' ) ) 18 { 19 *dest++ = *src++; 20 } 21 return tmp; 25 22 } 26 *//trunk/functions/string/strcoll.c
r13 r25 6 6 // ---------------------------------------------------------------------------- 7 7 8 int strcoll( const char * s1, const char * s2 ) { /* TODO */ }; 8 // TODO: Dummy function, does not support locales. 9 9 10 /* PDPC code - unreviewed 10 int strcmp( const char * src_1, const char * src_2 ); 11 12 int strcoll( const char * src_1, const char * src_2 ) 11 13 { 12 return (strcmp(s1, s2));14 return strcmp( src_1, src_2 ); 13 15 } 14 *//trunk/functions/string/strerror.c
r13 r25 6 6 // ---------------------------------------------------------------------------- 7 7 8 char * strerror( int errcode ) { /* TODO */ }; 8 #include <errno.h> 9 9 10 /* PDPC code - unreviewed 10 char * strerror( int errcode ) 11 11 { 12 if (errnum == 0) return ("No error has occurred\n"); 13 else return ("An error has occurred\n"); 12 switch ( errcode ) 13 { 14 case 0: 15 return "no error"; 16 break; 17 case EDOM: 18 return "domain error"; 19 break; 20 case EILSEQ: 21 return "illegal sequence"; 22 break; 23 case ERANGE: 24 return "range error"; 25 break; 26 default: 27 return "unknown error"; 28 break; 29 } 14 30 } 15 *//trunk/functions/string/strcpy.c
r13 r25 6 6 // ---------------------------------------------------------------------------- 7 7 8 char * strcpy( char * restrict s1, const char * restrict s2 ) { /* TODO */ }; 9 10 /* Therx code - unreviewed 8 char * strcpy( char * restrict dest, const char * restrict src ) 11 9 { 12 while (*s1++ = *s2++) 10 char * tmp = dest; 11 while ( ( *dest++ = *src++ ) != '\0' ) 13 12 { 14 13 // EMPTY 15 14 } 16 return s1;15 return tmp; 17 16 } 18 */19 20 /* PDPC code - unreviewed21 char *strcpy(char *s1, const char *s2)22 {23 char *p = s1;24 25 while ((*p++ = *s2++) != '\0') ;26 return (s1);27 }28 *//trunk/functions/string/strncmp.c
r13 r25 6 6 // ---------------------------------------------------------------------------- 7 7 8 int strncmp( const char * s1, const char * s2, size_t n ) { /* TODO */ }; 8 #include <__size_t.h> 9 9 10 /* PDPC code - unreviewed 10 int strncmp( const char * src_1, const char * src_2, size_t n ) 11 11 { 12 const unsigned char *p1; 13 const unsigned char *p2; 14 size_t x = 0; 15 16 p1 = (const unsigned char *)s1; 17 p2 = (const unsigned char *)s2; 18 while (x < n) 12 while ( ( n-- != 0 ) && ( *src_1 == *src_2 ) ) 19 13 { 20 if (p1[x] < p2[x]) return (-1); 21 else if (p1[x] > p2[x]) return (1); 22 else if (p1[x] == '\0') return (0); 23 x++; 14 ++src_1; 15 ++src_2; 24 16 } 25 return (0); 17 if ( ( n == 0 ) ) 18 { 19 return 0; 20 } 21 return ( *src_1 - *src_2 ); 26 22 } 27 *//trunk/functions/string/strpbrk.c
r13 r25 6 6 // ---------------------------------------------------------------------------- 7 7 8 // ---------------------------------------------------------------------------- 9 // C++ 8 #include <__NULL.h> 10 9 11 const char * strpbrk( const char * s1, const char * s2 ) { /* TODO */ }; 12 char * strpbrk( char * s1, const char * s2 ) { /* TODO */ }; 13 14 // ---------------------------------------------------------------------------- 15 // Standard C 16 17 char * strpbrk( const char *s1, const char * s2 ) { /* TODO */ }; 18 19 /* PDPC code - unreviewed 10 char * strpbrk( const char *src_1, const char * src_2 ) 20 11 { 21 const char *p1; 22 const char *p2; 23 24 p1 = s1; 25 while (*p1 != '\0') 12 const char * p1 = src_1; 13 const char * p2; 14 while ( *p1 != '\0' ) 26 15 { 27 p2 = s 2;28 while ( *p2 != '\0')16 p2 = src_2; 17 while ( *p2 != '\0' ) 29 18 { 30 if (*p1 == *p2) return ((char *)p1); 31 p2++; 19 if ( *p1 == *p2++ ) 20 { 21 return (char *) p1; 22 } 32 23 } 33 p1++;24 ++p1; 34 25 } 35 return (NULL);26 return NULL; 36 27 } 37 *//trunk/functions/string/strrchr.c
r13 r25 6 6 // ---------------------------------------------------------------------------- 7 7 8 // ---------------------------------------------------------------------------- 9 // C++ 8 #include <__NULL.h> 10 9 11 const char * strrchr( const char * s, int c ) { /* TODO */ }; 12 char * strrchr( char * s, int c ) { /* TODO */ }; 13 14 // ---------------------------------------------------------------------------- 15 // Standard C 16 17 char * strrchr( const char * s, int c ) { /* TODO */ }; 18 19 /* PDPC code - unreviewed 10 char * strrchr( const char * src, int c ) 20 11 { 21 const char *p; 22 23 p = s + strlen(s); 24 while (p >= s) 12 const char * p = src; 13 while ( *p != '\0' ) 25 14 { 26 if (*p == (char)c) return ((char *)p); 27 p--; 15 ++p; 28 16 } 29 return (NULL); 17 while ( p >= src ) 18 { 19 if ( *p == (char) c ) 20 { 21 return (char *) p; 22 } 23 --p; 24 } 25 return NULL; 30 26 } 31 *//trunk/functions/string/strspn.c
r13 r25 6 6 // ---------------------------------------------------------------------------- 7 7 8 size_t strspn( const char * s1, const char * s2 ) { /* TODO */ }; 8 #include <__size_t.h> 9 9 10 /* PDPC code - unreviewed 10 size_t strspn( const char * src_1, const char * src_2 ) 11 11 { 12 const char *p1; 13 const char *p2; 14 15 p1 = s1; 16 while (*p1 != '\0') 12 size_t len = 0; 13 const char * p; 14 while ( src_1[ len ] != '\0' ) 17 15 { 18 p 2 = s2;19 while ( *p2 != '\0')16 p = src_2; 17 while ( *p != '\0' ) 20 18 { 21 if (*p1 == *p2) break; 22 p2++; 19 if ( *src_1 == *p ) 20 { 21 break; 22 } 23 ++p; 23 24 } 24 if (*p2 == '\0') return ((size_t)(p1 - s1)); 25 p1++; 25 if ( *p == '\0' ) 26 { 27 return len; 28 } 29 ++len; 26 30 } 27 return ((size_t)(p1 - s1));31 return len; 28 32 } 29 *//trunk/functions/string/memset.c
r20 r22 6 6 // ---------------------------------------------------------------------------- 7 7 8 #include < string.h>8 #include <__size_t.h> 9 9 10 10 void * memset( void * dest, int c, size_t n ) /trunk/functions/string/memcpy.c
r19 r22 6 6 // ---------------------------------------------------------------------------- 7 7 8 #include < string.h>8 #include <__size_t.h> 9 9 10 10 void * memcpy( void * restrict dest, const void * restrict src, size_t n ) /trunk/functions/string/strcspn.c
r13 r25 6 6 // ---------------------------------------------------------------------------- 7 7 8 size_t strcspn( const char * s1, const char * s2 ) { /* TODO */ }; 8 #include <__size_t.h> 9 9 10 /* PDPC code - unreviewed 10 size_t strcspn( const char * src_1, const char * src_2 ) 11 11 { 12 const char *p1; 13 const char *p2; 14 15 p1 = s1; 16 while (*p1 != '\0') 12 size_t len = 0; 13 const char * src_p; 14 while ( src_1[len] != '\0' ) 17 15 { 18 p2 = s2;19 while ( *p2 != '\0')16 src_p = src_2; 17 while ( *src_p != '\0' ) 20 18 { 21 if (*p1 == *p2) return ((size_t)(p1 - s1)); 22 p2++; 19 if ( src_1[len] == *src_p++ ) 20 { 21 return len; 22 } 23 23 } 24 p1++;24 ++len; 25 25 } 26 return ((size_t)(p1 - s1));26 return len; 27 27 } 28 */
