projects
/
paraslash.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Some more aacdec cleanups
[paraslash.git]
/
string.c
diff --git
a/string.c
b/string.c
index fba36e5fcc6f92ca1542fd9b5989f61099ad584a..78b862c933ced61396aadb6df04f43d8185eee21 100644
(file)
--- a/
string.c
+++ b/
string.c
@@
-18,13
+18,16
@@
/** \file string.c memory allocation and string handling functions */
/** \file string.c memory allocation and string handling functions */
-#include <sys/time.h> /* gettimeofday */
#include "para.h"
#include "para.h"
+#include "string.h"
+
+#include <sys/time.h> /* gettimeofday */
#include <regex.h>
#include <pwd.h>
#include <sys/utsname.h> /* uname() */
#include <regex.h>
#include <pwd.h>
#include <sys/utsname.h> /* uname() */
+#include <string.h>
+
#include "error.h"
#include "error.h"
-#include "string.h"
/**
* paraslash's version of realloc()
/**
* paraslash's version of realloc()
@@
-379,32
+382,35
@@
__must_check __malloc char *para_homedir(void)
*
* \return The number of substrings found in \a args.
*/
*
* \return The number of substrings found in \a args.
*/
-__must_check unsigned split_args(char *args, char ***argv_ptr, int delim)
+
+__must_check unsigned split_args(char *args, char ***argv_ptr, const char *delim)
{
char *p = args;
char **argv;
{
char *p = args;
char **argv;
- s
size_t n = 0, i
;
+ s
ize_t n = 0, i, j
;
- while (
p && (p = strchr(p, delim)
)) {
- p
++
;
+ while (
(i = strcspn(p, delim)) && (p += i
)) {
+ p
+= strspn(p, delim)
;
n++;
}
n++;
}
- *argv_ptr = para_
calloc((n + 3
) * sizeof(char *));
+ *argv_ptr = para_
malloc((n + 1
) * sizeof(char *));
argv = *argv_ptr;
i = 0;
p = args;
argv = *argv_ptr;
i = 0;
p = args;
-// printf("split_args: a:%s\n", p);
while (p) {
argv[i] = p;
while (p) {
argv[i] = p;
- p = strchr(p, delim);
- if (p) {
-// printf("a:%s\n", p);
+ j = strcspn(p, delim);
+ if (!j)
+ break;
+ p += strcspn(p, delim);
+ if (*p) {
*p = '\0';
*p = '\0';
-// printf("b:\n");
p++;
p++;
-
i++
;
+
p += strspn(p, delim)
;
}
}
+ i++;
}
}
+ argv[n] = NULL;
return n;
}
return n;
}