libutil/libu2s: Move strlcpy() implementation to libutils

The strlcpy() implementation in libu2s is beneficial for other tools as
well. Move the implementation to libutils and replace misc_strlcpy() in
libu2s accordingly.

Change the link order in zipl to make it build again.

Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Jan Höppner
2018-11-07 14:20:40 +01:00
parent a208463e49
commit aefc8cd3ff
7 changed files with 35 additions and 49 deletions
+2 -2
View File
@@ -4,9 +4,9 @@ lib = libu2s.a
all: $(lib)
objects = u2s.o misc.o
objects = u2s.o
$(lib): $(objects)
$(lib): $(objects) $(rootdir)/libutil/libutil.a
install: all
-27
View File
@@ -1,27 +0,0 @@
/*
* Misc - Local helper functions
*
* Copyright IBM Corp. 2016, 2017
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#include <string.h>
#include "lib/util_base.h"
/*
* Helper function that copies a string safely
*/
size_t misc_strlcpy(char *dest, const char *src, size_t size)
{
size_t str_len = strlen(src);
size_t len;
if (size) {
len = MIN(size - 1, str_len);
memcpy(dest, src, len);
dest[len] = '\0';
}
return str_len;
}
-15
View File
@@ -1,15 +0,0 @@
/*
* Misc - Local helper functions
*
* Copyright IBM Corp. 2016, 2017
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#ifndef MISC_H
#define MISC_H
size_t misc_strlcpy(char *, const char *, size_t);
#endif /* MISC_H */
+3 -3
View File
@@ -20,7 +20,7 @@
#include <wait.h>
#include "lib/u2s.h"
#include "misc.h"
#include "lib/util_libc.h"
#define DEV_BUFFER_LENGTH 20
#define PATH_BUFFER_LENGTH 256
@@ -113,7 +113,7 @@ static int extract_busid(char *name, char *busid) {
if (!start)
return -1;
start++;
len = misc_strlcpy(busid, start, BUSIDSIZE);
len = util_strlcpy(busid, start, BUSIDSIZE);
if (len >= BUSIDSIZE)
return -1;
@@ -246,7 +246,7 @@ static int find_busid_in_proc(int maja, int mina, char *busid)
while (fscanf(filp, "%[^(] %*[^)] ) at ( %d : %d %*[^\n]\n",
bus, &majb, &minb) != EOF) {
if ((maja == majb) && (mina == minb)) {
len = misc_strlcpy(busid, bus, BUSIDSIZE);
len = util_strlcpy(busid, bus, BUSIDSIZE);
if (len < BUSIDSIZE)
rc = 0;
break;