Commit a8bfb94c authored by Paolo 'Blaisorblade' Giarrusso's avatar Paolo 'Blaisorblade' Giarrusso Committed by Linus Torvalds

[PATCH] strlcat: use for uml umid.c

Simplify the code by using strlcat() instead of strncat() and manual
appending.
Signed-off-by: default avatarPaolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Cc: Jeff Dike <jdike@addtoit.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 3a02d6c0
...@@ -14,7 +14,9 @@ extern void *um_kmalloc_atomic(int size); ...@@ -14,7 +14,9 @@ extern void *um_kmalloc_atomic(int size);
extern void kfree(void *ptr); extern void kfree(void *ptr);
extern int in_aton(char *str); extern int in_aton(char *str);
extern int open_gdb_chan(void); extern int open_gdb_chan(void);
extern int strlcpy(char *, const char *, int); /* These use size_t, however unsigned long is correct on both i386 and x86_64. */
extern unsigned long strlcpy(char *, const char *, unsigned long);
extern unsigned long strlcat(char *, const char *, unsigned long);
extern void *um_vmalloc(int size); extern void *um_vmalloc(int size);
extern void vfree(void *ptr); extern void vfree(void *ptr);
......
...@@ -237,16 +237,13 @@ static int __init make_uml_dir(void) ...@@ -237,16 +237,13 @@ static int __init make_uml_dir(void)
strlcpy(dir, home, sizeof(dir)); strlcpy(dir, home, sizeof(dir));
uml_dir++; uml_dir++;
} }
strlcat(dir, uml_dir, sizeof(dir));
len = strlen(dir); len = strlen(dir);
strncat(dir, uml_dir, sizeof(dir) - len); if (len > 0 && dir[len - 1] != '/')
len = strlen(dir); strlcat(dir, "/", sizeof(dir));
if((len > 0) && (len < sizeof(dir) - 1) && (dir[len - 1] != '/')){
dir[len] = '/';
dir[len + 1] = '\0';
}
uml_dir = malloc(strlen(dir) + 1); uml_dir = malloc(strlen(dir) + 1);
if(uml_dir == NULL){ if (uml_dir == NULL) {
printf("make_uml_dir : malloc failed, errno = %d\n", errno); printf("make_uml_dir : malloc failed, errno = %d\n", errno);
exit(1); exit(1);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment