[PATCH] strdup() clean up for 2.3.10

Steve Dodd (dirk@loth.demon.co.uk)
Tue, 20 Jul 1999 02:45:40 +0100


Hi,

I went to add a strdup() to lib/string.c and then found a couple of places
which already defined one, so a quick clean up patch is below. It'll probably
apply to 2.2.10, with the exception of parport_probe.c.

Index: drivers/misc/parport_probe.c
===================================================================
RCS file: /usr/local/cvsroot/linux/drivers/misc/Attic/parport_probe.c,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 parport_probe.c
--- drivers/misc/parport_probe.c 1999/07/18 11:34:57 1.1.2.1
+++ drivers/misc/parport_probe.c 1999/07/20 00:29:09
@@ -46,14 +46,6 @@
printk("\n");
}

-static char *strdup(char *str)
-{
- int n = strlen(str)+1;
- char *s = kmalloc(n, GFP_KERNEL);
- if (!s) return NULL;
- return strcpy(s, str);
-}
-
static void parse_data(struct parport *port, int device, char *str)
{
char *txt = kmalloc(strlen(str)+1, GFP_KERNEL);
Index: include/linux/string.h
===================================================================
RCS file: /usr/local/cvsroot/linux/include/linux/string.h,v
retrieving revision 1.1.1.2
diff -u -r1.1.1.2 string.h
--- include/linux/string.h 1999/07/18 11:23:25 1.1.1.2
+++ include/linux/string.h 1999/07/20 00:02:31
@@ -28,6 +28,7 @@
extern int strcmp(const char *,const char *);
extern int strncmp(const char *,const char *,__kernel_size_t);
extern int strnicmp(const char *, const char *, __kernel_size_t);
+extern char * strdup(const char *);

extern void * memset(void *,int,__kernel_size_t);
extern void * memcpy(void *,const void *,__kernel_size_t);
Index: include/net/irda/irias_object.h
===================================================================
RCS file: /usr/local/cvsroot/linux/include/net/irda/irias_object.h,v
retrieving revision 1.1.1.2
diff -u -r1.1.1.2 irias_object.h
--- include/net/irda/irias_object.h 1999/05/18 04:54:34 1.1.1.2
+++ include/net/irda/irias_object.h 1999/07/20 00:37:20
@@ -72,8 +72,6 @@
struct ias_value *value; /* Attribute value */
};

-char *strdup( char *str);
-
struct ias_object *irias_new_object( char *name, int id);
void irias_insert_object( struct ias_object *obj);
void __irias_delete_object( struct ias_object *obj);
Index: kernel/ksyms.c
===================================================================
RCS file: /usr/local/cvsroot/linux/kernel/ksyms.c,v
retrieving revision 1.1.1.14
diff -u -r1.1.1.14 ksyms.c
--- kernel/ksyms.c 1999/07/18 11:36:12 1.1.1.14
+++ kernel/ksyms.c 1999/07/19 23:58:35
@@ -409,3 +410,4 @@

/* library functions */
EXPORT_SYMBOL(strnicmp);
+EXPORT_SYMBOL(strdup);
Index: lib/string.c
===================================================================
RCS file: /usr/local/cvsroot/linux/lib/string.c,v
retrieving revision 1.1.1.3
diff -u -r1.1.1.3 string.c
--- lib/string.c 1999/07/18 11:36:15 1.1.1.3
+++ lib/string.c 1999/07/20 00:41:07
@@ -17,6 +17,7 @@

#include <linux/types.h>
#include <linux/string.h>
+#include <linux/malloc.h>
#include <linux/ctype.h>

#ifndef __HAVE_ARCH_STRNICMP
@@ -374,5 +375,14 @@
}
return NULL;
}
+#endif

+#ifndef __HAVE_ARCH_STRDUP
+char *strdup(const char *str)
+{
+ int n = strlen(str)+1;
+ char *s = kmalloc(n, GFP_KERNEL);
+ if (!s) return NULL;
+ return strcpy(s, str);
+}
#endif
Index: net/irda/irias_object.c
===================================================================
RCS file: /usr/local/cvsroot/linux/net/irda/irias_object.c,v
retrieving revision 1.1.1.3
diff -u -r1.1.1.3 irias_object.c
--- net/irda/irias_object.c 1999/05/19 21:07:41 1.1.1.3
+++ net/irda/irias_object.c 1999/07/20 00:33:16
@@ -40,30 +40,6 @@
};

/*
- * Function strdup (str)
- *
- * My own kernel version of strdup!
- *
- */
-char *strdup( char *str)
-{
- char *new_str;
-
- if ( str == NULL)
- return NULL;
-
- ASSERT( strlen( str) < 64, return NULL;);
-
- new_str = kmalloc( strlen( str)+1, GFP_ATOMIC);
- if ( new_str == NULL)
- return NULL;
-
- strcpy( new_str, str);
-
- return new_str;
-}
-
-/*
* Function ias_new_object (name, id)
*
* Create a new IAS object

-- 
No good deed goes unpunished.

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/