mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
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:
@@ -130,6 +130,7 @@ char *util_strcat_realloc(char *str1, const char *str2);
|
|||||||
void util_str_toupper(char *str);
|
void util_str_toupper(char *str);
|
||||||
|
|
||||||
char *util_strstrip(char *s);
|
char *util_strstrip(char *s);
|
||||||
|
size_t util_strlcpy(char *dest, const char *src, size_t size);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ lib = libu2s.a
|
|||||||
|
|
||||||
all: $(lib)
|
all: $(lib)
|
||||||
|
|
||||||
objects = u2s.o misc.o
|
objects = u2s.o
|
||||||
|
|
||||||
$(lib): $(objects)
|
$(lib): $(objects) $(rootdir)/libutil/libutil.a
|
||||||
|
|
||||||
install: all
|
install: all
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
|
||||||
}
|
|
||||||
@@ -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 */
|
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
#include <wait.h>
|
#include <wait.h>
|
||||||
|
|
||||||
#include "lib/u2s.h"
|
#include "lib/u2s.h"
|
||||||
#include "misc.h"
|
#include "lib/util_libc.h"
|
||||||
|
|
||||||
#define DEV_BUFFER_LENGTH 20
|
#define DEV_BUFFER_LENGTH 20
|
||||||
#define PATH_BUFFER_LENGTH 256
|
#define PATH_BUFFER_LENGTH 256
|
||||||
@@ -113,7 +113,7 @@ static int extract_busid(char *name, char *busid) {
|
|||||||
if (!start)
|
if (!start)
|
||||||
return -1;
|
return -1;
|
||||||
start++;
|
start++;
|
||||||
len = misc_strlcpy(busid, start, BUSIDSIZE);
|
len = util_strlcpy(busid, start, BUSIDSIZE);
|
||||||
if (len >= BUSIDSIZE)
|
if (len >= BUSIDSIZE)
|
||||||
return -1;
|
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",
|
while (fscanf(filp, "%[^(] %*[^)] ) at ( %d : %d %*[^\n]\n",
|
||||||
bus, &majb, &minb) != EOF) {
|
bus, &majb, &minb) != EOF) {
|
||||||
if ((maja == majb) && (mina == minb)) {
|
if ((maja == majb) && (mina == minb)) {
|
||||||
len = misc_strlcpy(busid, bus, BUSIDSIZE);
|
len = util_strlcpy(busid, bus, BUSIDSIZE);
|
||||||
if (len < BUSIDSIZE)
|
if (len < BUSIDSIZE)
|
||||||
rc = 0;
|
rc = 0;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -228,3 +228,30 @@ char *util_strstrip(char *s)
|
|||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy \a src to buffer \a dest of size \a size. At most size - 1
|
||||||
|
* chars will be copied. \a dest will always be NUL terminated.
|
||||||
|
*
|
||||||
|
* Note: If the return value is greater than or equal to size truncation
|
||||||
|
* occurred.
|
||||||
|
*
|
||||||
|
* @param[in] dest Destination buffer
|
||||||
|
* @param[in] src Source string
|
||||||
|
* @param[in] size Size of destination buffer
|
||||||
|
*
|
||||||
|
* @returns strlen Length of \a src string
|
||||||
|
*/
|
||||||
|
size_t util_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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ ALL_CPPFLAGS += -I../include -I../boot \
|
|||||||
-D_FILE_OFFSET_BITS=64 $(NO_PIE_CFLAGS)
|
-D_FILE_OFFSET_BITS=64 $(NO_PIE_CFLAGS)
|
||||||
ALL_LDFLAGS += -Wl,-z,noexecstack $(NO_PIE_LDFLAGS)
|
ALL_LDFLAGS += -Wl,-z,noexecstack $(NO_PIE_LDFLAGS)
|
||||||
|
|
||||||
libs = $(rootdir)/libutil/libutil.a \
|
libs = $(rootdir)/libu2s/libu2s.a \
|
||||||
$(rootdir)/libu2s/libu2s.a
|
$(rootdir)/libutil/libutil.a
|
||||||
|
|
||||||
objects = misc.o error.o scan.o job.o boot.o bootmap.o disk.o \
|
objects = misc.o error.o scan.o job.o boot.o bootmap.o disk.o \
|
||||||
install.o zipl.o $(rootdir)/zipl/boot/data.o
|
install.o zipl.o $(rootdir)/zipl/boot/data.o
|
||||||
|
|||||||
Reference in New Issue
Block a user