Bläddra i källkod

Merge branch 'master' into iscsi-update

tags/v0.9.3
Michael Brown 17 år sedan
förälder
incheckning
cc80750694
4 ändrade filer med 52 tillägg och 13 borttagningar
  1. 8
    8
      src/core/refcnt.c
  2. 41
    4
      src/core/string.c
  3. 1
    1
      src/include/gpxe/refcnt.h
  4. 2
    0
      src/include/string.h

+ 8
- 8
src/core/refcnt.c Visa fil

@@ -29,18 +29,18 @@
29 29
  * Increment reference count
30 30
  *
31 31
  * @v refcnt		Reference counter, or NULL
32
+ * @ret refcnt		Reference counter
32 33
  *
33 34
  * If @c refcnt is NULL, no action is taken.
34 35
  */
35
-void ref_get ( struct refcnt *refcnt ) {
36
+struct refcnt * ref_get ( struct refcnt *refcnt ) {
36 37
 
37
-	if ( ! refcnt )
38
-		return;
39
-
40
-	refcnt->refcnt++;
41
-
42
-	DBGC2 ( refcnt, "REFCNT %p incremented to %d\n",
43
-		refcnt, refcnt->refcnt );
38
+	if ( refcnt ) {
39
+		refcnt->refcnt++;
40
+		DBGC2 ( refcnt, "REFCNT %p incremented to %d\n",
41
+			refcnt, refcnt->refcnt );
42
+	}
43
+	return refcnt;
44 44
 }
45 45
 
46 46
 /**

+ 41
- 4
src/core/string.c Visa fil

@@ -279,6 +279,31 @@ size_t strspn(const char *s, const char *accept)
279 279
 }
280 280
 #endif
281 281
 
282
+#ifndef __HAVE_ARCH_STRCSPN
283
+/**
284
+ * strcspn - Calculate the length of the initial substring of @s which only
285
+ * 	contain letters not in @reject
286
+ * @s: The string to be searched
287
+ * @accept: The string to search for
288
+ */
289
+size_t strcspn(const char *s, const char *reject)
290
+{
291
+	const char *p;
292
+	const char *r;
293
+	size_t count = 0;
294
+
295
+	for (p = s; *p != '\0'; ++p) {
296
+		for (r = reject; *r != '\0'; ++r) {
297
+			if (*p == *r)
298
+				return count;
299
+		}
300
+		++count;
301
+	}
302
+
303
+	return count;
304
+}
305
+#endif
306
+
282 307
 #ifndef __HAVE_ARCH_STRPBRK
283 308
 /**
284 309
  * strpbrk - Find the first occurrence of a set of characters
@@ -541,9 +566,21 @@ void * memchr(const void *s, int c, size_t n)
541 566
 
542 567
 #endif
543 568
 
544
-char * strdup(const char *s) {
545
-	char *new = malloc(strlen(s)+1);
546
-	if (new)
547
-		strcpy(new,s);
569
+char * strndup(const char *s, size_t n)
570
+{
571
+	size_t len = strlen(s);
572
+	char *new;
573
+
574
+	if (len>n)
575
+		len = n;
576
+	new = malloc(len+1);
577
+	if (new) {
578
+		new[len] = '\0';
579
+		memcpy(new,s,len);
580
+	}
548 581
 	return new;
549 582
 }
583
+
584
+char * strdup(const char *s) {
585
+	return strndup(s, ~((size_t)0));
586
+}

+ 1
- 1
src/include/gpxe/refcnt.h Visa fil

@@ -38,7 +38,7 @@ struct refcnt {
38 38
 	void ( * free ) ( struct refcnt *refcnt );
39 39
 };
40 40
 
41
-extern void ref_get ( struct refcnt *refcnt );
41
+extern struct refcnt * ref_get ( struct refcnt *refcnt );
42 42
 extern void ref_put ( struct refcnt *refcnt );
43 43
 
44 44
 #endif /* _GPXE_REFCNT_H */

+ 2
- 0
src/include/string.h Visa fil

@@ -30,6 +30,7 @@ char * strrchr(const char * s, int c);
30 30
 size_t strlen(const char * s);
31 31
 size_t strnlen(const char * s, size_t count);
32 32
 size_t strspn(const char *s, const char *accept);
33
+size_t strcspn(const char *s, const char *reject);
33 34
 char * strpbrk(const char * cs,const char * ct);
34 35
 char * strtok(char * s,const char * ct);
35 36
 char * strsep(char **s, const char *ct);
@@ -41,6 +42,7 @@ void * memscan(void * addr, int c, size_t size);
41 42
 char * strstr(const char * s1,const char * s2);
42 43
 void * memchr(const void *s, int c, size_t n);
43 44
 char * strdup(const char *s);
45
+char * strndup(const char *s, size_t n);
44 46
 
45 47
 extern const char * strerror ( int errno );
46 48
 

Laddar…
Avbryt
Spara