Browse Source

Merge branch 'master' into iscsi-update

tags/v0.9.3
Michael Brown 17 years ago
parent
commit
cc80750694
4 changed files with 52 additions and 13 deletions
  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 View File

29
  * Increment reference count
29
  * Increment reference count
30
  *
30
  *
31
  * @v refcnt		Reference counter, or NULL
31
  * @v refcnt		Reference counter, or NULL
32
+ * @ret refcnt		Reference counter
32
  *
33
  *
33
  * If @c refcnt is NULL, no action is taken.
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 View File

279
 }
279
 }
280
 #endif
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
 #ifndef __HAVE_ARCH_STRPBRK
307
 #ifndef __HAVE_ARCH_STRPBRK
283
 /**
308
 /**
284
  * strpbrk - Find the first occurrence of a set of characters
309
  * strpbrk - Find the first occurrence of a set of characters
541
 
566
 
542
 #endif
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
 	return new;
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 View File

38
 	void ( * free ) ( struct refcnt *refcnt );
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
 extern void ref_put ( struct refcnt *refcnt );
42
 extern void ref_put ( struct refcnt *refcnt );
43
 
43
 
44
 #endif /* _GPXE_REFCNT_H */
44
 #endif /* _GPXE_REFCNT_H */

+ 2
- 0
src/include/string.h View File

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

Loading…
Cancel
Save