mirror of
git://git.code.sf.net/p/dhcpd-pools/code
synced 2025-12-16 15:57:00 +00:00
getdata: memccpy() is better than own similar function
The memccpy() is maintained in libc so there is no reason to reimplement similar functionality within this software. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
parent
5189333c95
commit
5b8ad97611
2 changed files with 7 additions and 26 deletions
|
|
@ -193,12 +193,6 @@ int parse_leases(void);
|
|||
void parse_config(int, const char *__restrict,
|
||||
struct shared_network_t *__restrict)
|
||||
__attribute__ ((nonnull(2, 3)));
|
||||
void nth_field(char *__restrict dest, const char *__restrict src)
|
||||
__attribute__ ((nonnull(1, 2)))
|
||||
# if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
|
||||
__attribute__ ((__hot__))
|
||||
# endif
|
||||
;
|
||||
int prepare_data(void);
|
||||
int do_counting(void);
|
||||
void flip_ranges(struct range_t *__restrict ranges,
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@
|
|||
int parse_leases(void)
|
||||
{
|
||||
FILE *dhcpd_leases;
|
||||
char *line, *ipstring, macstring[20];
|
||||
char *line, *ipstring, macstring[20], *stop;
|
||||
union ipaddr_t addr;
|
||||
struct stat lease_file_stats;
|
||||
bool ethernets = false;
|
||||
|
|
@ -109,7 +109,11 @@ int parse_leases(void)
|
|||
switch(xstrstr(line)) {
|
||||
/* It's a lease, save IP */
|
||||
case PREFIX_LEASE:
|
||||
nth_field(ipstring, line + (config.dhcp_version == VERSION_4 ? 6 : 9));
|
||||
stop = memccpy(ipstring, line + (config.dhcp_version == VERSION_4 ? 6 : 9), ' ', strlen(line));
|
||||
if (stop != NULL) {
|
||||
--stop;
|
||||
*stop = '\0';
|
||||
}
|
||||
parse_ipaddr(ipstring, &addr);
|
||||
break;
|
||||
case PREFIX_BINDING_STATE_FREE:
|
||||
|
|
@ -139,7 +143,7 @@ int parse_leases(void)
|
|||
case PREFIX_HARDWARE_ETHERNET:
|
||||
if (ethernets == false)
|
||||
break;
|
||||
nth_field(macstring, line + 20);
|
||||
memcpy(macstring, line + 20, 17);
|
||||
macstring[17] = '\0';
|
||||
if ((lease = find_lease(&addr)) != NULL) {
|
||||
lease->ethernet = xstrdup(macstring);
|
||||
|
|
@ -156,23 +160,6 @@ int parse_leases(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*! \brief A version of strcpy, but for a white space separated field.
|
||||
* \param dest String copy destination.
|
||||
* \param src String copy source.
|
||||
*/
|
||||
void nth_field(char *restrict dest, const char *restrict src)
|
||||
{
|
||||
size_t i, len;
|
||||
len = strlen(src);
|
||||
for (i = 0; i < len; i++) {
|
||||
dest[i] = src[i];
|
||||
if (unlikely(src[i] == ' ')) {
|
||||
dest[i] = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*! \brief Keyword search in dhcpd.conf file.
|
||||
* \param s A line from the dhcpd.conf file.
|
||||
* \return Indicator what configuration was found. */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue