Re: [PATCH] (revision 1) Remove isys/str.c, replace calls with glib.h or string.h calls.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Mon, 22 Mar 2010, David Cantrell wrote:

str.c was from a time when loader was still a statically linked binary.
Times have changed.  Removed str.c and replaced calls with either
string.h or glib.h functions.

For g_ascii_strup() and g_ascii_strdown(), those functions dup the
passed in string, change it, and return that.
---
isys/Makefile.am |    2 +-
isys/iface.c     |    5 +-
isys/str.c       |  125 ------------------------------------------------------
isys/str.h       |   29 ------------
loader/loader.c  |    7 ++-
loader/net.c     |    9 +---
6 files changed, 11 insertions(+), 166 deletions(-)
delete mode 100644 isys/str.c
delete mode 100644 isys/str.h

diff --git a/isys/Makefile.am b/isys/Makefile.am
index f6a3247..f40a884 100644
--- a/isys/Makefile.am
+++ b/isys/Makefile.am
@@ -19,7 +19,7 @@

ISYS_SRCS = devices.c imount.c cpio.c uncpio.c lang.c \
            isofs.c linkdetect.c vio.c ethtool.c eddsupport.c iface.c \
-            str.c auditd.c log.c
+            auditd.c log.c

dist_noinst_HEADERS = *.h

diff --git a/isys/iface.c b/isys/iface.c
index c1251be..5897286 100644
--- a/isys/iface.c
+++ b/isys/iface.c
@@ -52,7 +52,6 @@

#include "isys.h"
#include "iface.h"
-#include "str.h"

/* Internal-only function prototypes. */
static struct nl_handle *_iface_get_handle(void);
@@ -303,7 +302,9 @@ char *iface_mac2str(char *ifname) {
    }

    if ((buf = nl_addr2str(addr, buf, buflen)) != NULL) {
-        buf = str2upper(buf);
+        char *oldbuf = buf;
+        buf = g_ascii_strup(buf, -1);
+        free(oldbuf);
    }

mac2str_error4:
diff --git a/isys/str.c b/isys/str.c
deleted file mode 100644
index cf05473..0000000
--- a/isys/str.c
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * str.c - String helper functions that don't need string.h or ctype.h
- *
- * Copyright (C) 2006  Red Hat, Inc.  All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- *
- * Author(s): David Cantrell <dcantrell@xxxxxxxxxx>
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "str.h"
-
-/**
- * Called by str2upper() or str2lower() to do the actual work.
- *
- * @param str String to convert.
- * @param lower Lower bound for the character range (e.g., a - z).
- * @param upper Upper bound for the character range (e.g., a - z).
- * @param shift Shift value (32 for lowercase, -32 for uppercase).
- * @return Pointer to str.
- */
-char *str2case(char *str, char lower, char upper, int shift) {
-    char *tmp;
-
-    if (str == NULL)
-        return NULL;
-
-    /* man ascii(7) */
-    tmp = str;
-    while (*tmp != '\0') {
-        if (*tmp >= lower && *tmp <= upper)
-            *tmp += shift;
-
-        tmp++;
-    }
-
-    return str;
-}
-
-/**
- * Convert given string to uppercase. Modifies the argument in the caller's
- * stack. If you must ask simply "why?" for this function, it's so we don't
- * need toupper() and the same for loop all over the place.
- *
- * LIMITATIONS: Only deals with ASCII character set.
- *
- * @param str String to convert to uppercase.
- * @return Pointer to str.
- */
-char *str2upper(char *str) {
-    return str2case(str, 'a', 'z', -32);
-}
-
-/**
- * Convert given string to lowercase. Modifies the argument in the caller's
- * stack. If you must ask simply "why?" for this function, it's so we don't
- * need tolower() and the same for loop all over the place.
- *
- * LIMITATIONS: Only deals with ASCII character set.
- *
- * @param str String to convert to lowercase.
- * @return Pointer to str.
- */
-char *str2lower(char *str) {
-    return str2case(str, 'A', 'Z', 32);
-}
-
-/**
- * Pretty much an exact copy of index(3) from the C library.
- * @param str String to scan.
- * @param ch Character to scan for.
- * @return Position of ch in str, NULL if not found.
- */
-char *strindex(char *str, int ch) {
-    if (str == NULL)
-        return NULL;
-
-    do {
-        if (*str == ch)
-            return str;
-        else
-            str++;
-    } while (*str != '\0');
-
-    return NULL;
-}
-
-/**
- * Return number of occurrences of a character in a string.
- * @param str String to scan.
- * @param ch Character to scan for.
- * @return Number of occurrences of ch in str.
- */
-int strcount(char *str, int ch) {
-    int retval = 0;
-    char *tmp = str;
-
-    if (tmp == NULL)
-        return retval;
-
-    do {
-        if ((tmp = strindex(tmp, ch)) != NULL) {
-            tmp++;
-            retval++;
-        }
-    } while (tmp != NULL);
-
-    return retval;
-}
-
-/* vim:set shiftwidth=4 softtabstop=4: */
diff --git a/isys/str.h b/isys/str.h
deleted file mode 100644
index d296021..0000000
--- a/isys/str.h
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * str.c - String helper functions, the header file
- *
- * Copyright (C) 2006  Red Hat, Inc.  All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- *
- * Author(s): David Cantrell <dcantrell@xxxxxxxxxx>
- */
-
-/* Function prototypes */
-char *str2case(char *str, char lower, char upper, int shift);
-char *str2upper(char *str);
-char *str2lower(char *str);
-int strcount(char *str, int ch);
-char *strindex(char *str, int ch);
-
-/* vim:set shiftwidth=4 softtabstop=4: */
diff --git a/loader/loader.c b/loader/loader.c
index 1f60160..8e5cb1d 100644
--- a/loader/loader.c
+++ b/loader/loader.c
@@ -98,7 +98,6 @@
#include "../isys/stubs.h"
#include "../isys/lang.h"
#include "../isys/eddsupport.h"
-#include "../isys/str.h"
#include "../isys/log.h"

/* maximum number of extra arguments that can be passed to the second stage */
@@ -847,10 +846,11 @@ static void parseCmdLineIpv6(struct loaderData_s * loaderData, char *argv)
     *     auto     RFC 2461 neighbor discovery
     */
    loaderData->ipv6 = NULL;
+    gchar *val = g_ascii_strdown(argv, -1);

-    if (!strncmp(str2lower(argv), "ipv6=dhcp", 9)) {
+    if (!strncmp(val, "ipv6=dhcp", 9)) {
        loaderData->ipv6 = strdup("dhcp");
-    } else if (!strncmp(str2lower(argv), "ipv6=auto", 9)) {
+    } else if (!strncmp(val, "ipv6=auto", 9)) {
        loaderData->ipv6 = strdup("auto");
    }

@@ -859,6 +859,7 @@ static void parseCmdLineIpv6(struct loaderData_s * loaderData, char *argv)
        flags |= LOADER_FLAGS_IPV6_PARAM;
    }

+    g_free(val);
    return;
}
#endif

Already revised the loader.c portion to this:

@@ -848,9 +847,9 @@ static void parseCmdLineIpv6(struct loaderData_s * loaderData, char *argv)
      */
     loaderData->ipv6 = NULL;
.
- -    if (!strncmp(str2lower(argv), "ipv6=dhcp", 9)) {
+    if (!strncasecmp(val, "ipv6=dhcp", 9)) {
         loaderData->ipv6 = strdup("dhcp");
- -    } else if (!strncmp(str2lower(argv), "ipv6=auto", 9)) {
+    } else if (!strncasecmp(val, "ipv6=auto", 9)) {
         loaderData->ipv6 = strdup("auto");
     }

diff --git a/loader/net.c b/loader/net.c
index 8796a68..afbc6d8 100644
--- a/loader/net.c
+++ b/loader/net.c
@@ -43,7 +43,6 @@
#include "../isys/isys.h"
#include "../isys/ethtool.h"
#include "../isys/iface.h"
-#include "../isys/str.h"
#include "../isys/log.h"

#include "lang.h"
@@ -1670,12 +1669,10 @@ int chooseNetworkInterface(struct loaderData_s * loaderData) {
    if (loaderData->netDev && (loaderData->netDev_set) == 1) {
        if ((loaderData->bootIf && (loaderData->bootIf_set) == 1) &&
            !strcasecmp(loaderData->netDev, "bootif")) {
-            ksMacAddr = strdup(loaderData->bootIf);
+            ksMacAddr = g_ascii_strup(loaderData->bootIf, -1);
        } else {
-            ksMacAddr = strdup(loaderData->netDev);
+            ksMacAddr = g_ascii_strup(loaderData->netDev, -1);
        }
-
-        ksMacAddr = str2upper(ksMacAddr);
    }

    for (i = 0; devs[i]; i++) {
@@ -2023,7 +2020,7 @@ void splitHostname (char *str, char **host, char **port)
        }
        else
            *host = strndup(str+1, rightbrack-1-str);
-    } else if (strcount(str, ':') > 1) {
+    } else if (strstr(str, ":")) {
        /* An IPv6 address without brackets.  Don't make the user surround the
         * address with brackets if there's no port number.
         */


- -- David Cantrell <dcantrell@xxxxxxxxxx>
Red Hat / Honolulu, HI

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iEYEARECAAYFAkun4noACgkQ5hsjjIy1VkkWgwCePswTekaEjj1GsPFqqRvUM252
ng8An1NJ8LnZRkcB7vVyGi1IEwiaAXqD
=0XgL
-----END PGP SIGNATURE-----

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux