Changeset 4cc0c9ee in mainline for uspace/app/bdsh/util.c
- Timestamp:
- 2009-01-22T14:22:12Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- bf226890
- Parents:
- fc11b8a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/util.c
rfc11b8a r4cc0c9ee 1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com> 2 * Copyright (C) 1998 by Wes Peters <wes@softweyr.com> 3 * Copyright (c) 1988, 1993 The Regents of the University of California. 4 * All rights reserved by all copyright holders. 1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com> - All rights reserved 5 2 * 6 3 * Redistribution and use in source and binary forms, with or without … … 31 28 */ 32 29 33 /* NOTES:34 * 1 - Various functions were adapted from FreeBSD (copyright holders noted above)35 * these functions are identified with comments.36 *37 * 2 - Some of these have since appeared in libc. They remain here for various38 * reasons, such as the eventual integration of garbage collection for things39 * that allocate memory and don't automatically free it.40 *41 * 3 - Things that expect a pointer to an allocated string do _no_ sanity checking42 * if developing on a simulator with no debugger, take care :)43 */44 45 30 #include <stdio.h> 46 31 #include <string.h> … … 54 39 55 40 extern volatile int cli_errno; 56 57 /* some platforms do not have strdup, implement it here.58 * Returns a pointer to an allocated string or NULL on failure */59 char * cli_strdup(const char *s1)60 {61 size_t len = strlen(s1) + 1;62 void *ret = malloc(len);63 64 if (ret == NULL) {65 cli_errno = CL_ENOMEM;66 return (char *) NULL;67 }68 69 cli_errno = CL_EOK;70 return (char *) memcpy(ret, s1, len);71 }72 73 /* Ported from FBSD strtok.c 8.1 (Berkeley) 6/4/93 */74 char * cli_strtok_r(char *s, const char *delim, char **last)75 {76 char *spanp, *tok;77 int c, sc;78 79 if (s == NULL && (s = *last) == NULL) {80 cli_errno = CL_EFAIL;81 return (NULL);82 }83 84 cont:85 c = *s++;86 for (spanp = (char *)delim; (sc = *spanp++) != 0;) {87 if (c == sc)88 goto cont;89 }90 91 if (c == 0) { /* no non-delimiter characters */92 *last = NULL;93 return (NULL);94 }95 96 tok = s - 1;97 98 for (;;) {99 c = *s++;100 spanp = (char *)delim;101 do {102 if ((sc = *spanp++) == c) {103 if (c == 0)104 s = NULL;105 else106 s[-1] = '\0';107 *last = s;108 return (tok);109 }110 } while (sc != 0);111 }112 }113 114 /* Ported from FBSD strtok.c 8.1 (Berkeley) 6/4/93 */115 char * cli_strtok(char *s, const char *delim)116 {117 static char *last;118 119 return (cli_strtok_r(s, delim, &last));120 }121 41 122 42 /* Count and return the # of elements in an array */
Note:
See TracChangeset
for help on using the changeset viewer.