From: Ralf Wildenhues Date: Tue, 5 Oct 2004 12:48:55 +0000 (+0000) Subject: * libltdl/ltdl.c (try_dlopen): Move .la file parsing X-Git-Tag: release-2-1b~927 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ba0dac4a9d8b97ece2b05fdc05ac057ac33260dd;p=thirdparty%2Flibtool.git * libltdl/ltdl.c (try_dlopen): Move .la file parsing part.. (parse_dotla_file): ..here. Adjust. --- diff --git a/ChangeLog b/ChangeLog index 259ac3030..6dd22d5cc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2004-10-05 Ralf Wildenhues + * libltdl/ltdl.c (try_dlopen): Move .la file parsing + part.. (parse_dotla_file): ..here. Adjust. + * libltdl/ltdl.c (load_deplibs, try_dlopen): Revert unnecessary casts to int from my patch from 2004-10-01. diff --git a/libltdl/ltdl.c b/libltdl/ltdl.c index 4c4225958..391598e67 100644 --- a/libltdl/ltdl.c +++ b/libltdl/ltdl.c @@ -913,6 +913,117 @@ trim (char **dest, const char *str) return 0; } +/* Read the .la file FILE. */ +static int +parse_dotla_file(FILE *file, char **dlname, char **libdir, char **deplibs, + char **old_name, int *installed) +{ + int errors = 0; + size_t line_len = LT_FILENAME_MAX; + char * line = MALLOC (char, line_len); + + if (!line) + { + LT__SETERROR (FILE_NOT_FOUND); + return 1; + } + + while (!feof (file)) + { + if (!fgets (line, (int) line_len, file)) + { + break; + } + + /* Handle the case where we occasionally need to read a line + that is longer than the initial buffer size. */ + while ((line[LT_STRLEN(line) -1] != '\n') && (!feof (file))) + { + line = REALLOC (char, line, line_len *2); + if (!line) + { + fclose (file); + ++errors; + goto cleanup; + } + if (!fgets (&line[line_len -1], (int) line_len +1, file)) + { + break; + } + line_len *= 2; + } + + if (line[0] == '\n' || line[0] == '#') + { + continue; + } + +#undef STR_DLNAME +#define STR_DLNAME "dlname=" + if (strncmp (line, STR_DLNAME, sizeof (STR_DLNAME) - 1) == 0) + { + errors += trim (dlname, &line[sizeof (STR_DLNAME) - 1]); + } + +#undef STR_OLD_LIBRARY +#define STR_OLD_LIBRARY "old_library=" + else if (strncmp (line, STR_OLD_LIBRARY, + sizeof (STR_OLD_LIBRARY) - 1) == 0) + { + errors += trim (old_name, &line[sizeof (STR_OLD_LIBRARY) - 1]); + } +#undef STR_LIBDIR +#define STR_LIBDIR "libdir=" + else if (strncmp (line, STR_LIBDIR, sizeof (STR_LIBDIR) - 1) == 0) + { + errors += trim (libdir, &line[sizeof(STR_LIBDIR) - 1]); + } + +#undef STR_DL_DEPLIBS +#define STR_DL_DEPLIBS "dependency_libs=" + else if (strncmp (line, STR_DL_DEPLIBS, + sizeof (STR_DL_DEPLIBS) - 1) == 0) + { + errors += trim (deplibs, &line[sizeof (STR_DL_DEPLIBS) - 1]); + } + else if (streq (line, "installed=yes\n")) + { + *installed = 1; + } + else if (streq (line, "installed=no\n")) + { + *installed = 0; + } + +#undef STR_LIBRARY_NAMES +#define STR_LIBRARY_NAMES "library_names=" + else if (!*dlname && strncmp (line, STR_LIBRARY_NAMES, + sizeof (STR_LIBRARY_NAMES) - 1) == 0) + { + char *last_libname; + errors += trim (dlname, &line[sizeof (STR_LIBRARY_NAMES) - 1]); + if (!errors + && *dlname + && (last_libname = strrchr (*dlname, ' ')) != 0) + { + last_libname = lt__strdup (last_libname + 1); + if (!last_libname) + { + ++errors; + goto cleanup; + } + MEMREASSIGN (*dlname, last_libname); + } + } + + if (errors) + return 1; + } +cleanup: + return errors; +} + +/* Try to open FILENAME as a module. */ static int try_dlopen (lt_dlhandle *phandle, const char *filename) { @@ -1025,8 +1136,6 @@ try_dlopen (lt_dlhandle *phandle, const char *filename) char * old_name = 0; char * libdir = 0; char * deplibs = 0; - char * line = 0; - size_t line_len; /* if we can't find the installed flag, it is probably an installed libtool archive, produced with an old version @@ -1082,110 +1191,12 @@ try_dlopen (lt_dlhandle *phandle, const char *filename) goto cleanup; } - line_len = LT_FILENAME_MAX; - line = MALLOC (char, line_len); - if (!line) - { - fclose (file); - ++errors; - goto cleanup; - } - /* read the .la file */ - while (!feof (file)) - { - if (!fgets (line, (int) line_len, file)) - { - break; - } - - /* Handle the case where we occasionally need to read a line - that is longer than the initial buffer size. */ - while ((line[LT_STRLEN(line) -1] != '\n') && (!feof (file))) - { - line = REALLOC (char, line, line_len *2); - if (!line) - { - fclose (file); - ++errors; - goto cleanup; - } - if (!fgets (&line[line_len -1], (int) line_len +1, file)) - { - break; - } - line_len *= 2; - } - - if (line[0] == '\n' || line[0] == '#') - { - continue; - } - -#undef STR_DLNAME -#define STR_DLNAME "dlname=" - if (strncmp (line, STR_DLNAME, sizeof (STR_DLNAME) - 1) == 0) - { - errors += trim (&dlname, &line[sizeof (STR_DLNAME) - 1]); - } - -#undef STR_OLD_LIBRARY -#define STR_OLD_LIBRARY "old_library=" - else if (strncmp (line, STR_OLD_LIBRARY, - sizeof (STR_OLD_LIBRARY) - 1) == 0) - { - errors += trim (&old_name, &line[sizeof (STR_OLD_LIBRARY) - 1]); - } -#undef STR_LIBDIR -#define STR_LIBDIR "libdir=" - else if (strncmp (line, STR_LIBDIR, sizeof (STR_LIBDIR) - 1) == 0) - { - errors += trim (&libdir, &line[sizeof(STR_LIBDIR) - 1]); - } - -#undef STR_DL_DEPLIBS -#define STR_DL_DEPLIBS "dependency_libs=" - else if (strncmp (line, STR_DL_DEPLIBS, - sizeof (STR_DL_DEPLIBS) - 1) == 0) - { - errors += trim (&deplibs, &line[sizeof (STR_DL_DEPLIBS) - 1]); - } - else if (streq (line, "installed=yes\n")) - { - installed = 1; - } - else if (streq (line, "installed=no\n")) - { - installed = 0; - } - -#undef STR_LIBRARY_NAMES -#define STR_LIBRARY_NAMES "library_names=" - else if (! dlname && strncmp (line, STR_LIBRARY_NAMES, - sizeof (STR_LIBRARY_NAMES) - 1) == 0) - { - char *last_libname; - errors += trim (&dlname, &line[sizeof (STR_LIBRARY_NAMES) - 1]); - if (!errors - && dlname - && (last_libname = strrchr (dlname, ' ')) != 0) - { - last_libname = lt__strdup (last_libname + 1); - if (!last_libname) - { - ++errors; - goto cleanup; - } - MEMREASSIGN (dlname, last_libname); - } - } - - if (errors) - break; - } + if (parse_dotla_file(file, &dlname, &libdir, &deplibs, + &old_name, &installed) != 0) + errors++; fclose (file); - FREE (line); /* allocate the handle */ *phandle = (lt_dlhandle) lt__zalloc (sizeof (lt__handle));