diff options
author | Pino Toscano <toscano.pino@tiscali.it> | 2013-04-26 16:12:12 +0200 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2013-04-26 23:06:25 +0200 |
commit | 848789c2d777e353e7c07320b68a7480beb107a6 (patch) | |
tree | 256d1c87d1d382f7e4053aa3a5aaac6ac8484777 | |
parent | ad7ec8f6be5bf3c9854168d6c2605fa07cacfc85 (diff) |
Use getline from POSIX.1-2008 when available
Ask the standard library to use POSIX.1-2008, and if available use its getline
function to read lines from the SDK configuration file.
If not, fallback on the current way (fgets with PATH_MAX-sized buffer), which
is now used only if PATH_MAX is defined.
If neither POSIX.1-2008 nor PATH_MAX are available, error out.
Change-Id: I8d2d256530d68884850535a6cd5908d1205035bc
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r-- | src/qtchooser/main.cpp | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/qtchooser/main.cpp b/src/qtchooser/main.cpp index f559bab..da54b16 100644 --- a/src/qtchooser/main.cpp +++ b/src/qtchooser/main.cpp @@ -48,6 +48,7 @@ */ #define _CRT_SECURE_NO_WARNINGS +#define _POSIX_C_SOURCE 200809L #include <set> #include <string> @@ -354,19 +355,43 @@ bool ToolWrapper::matchSdk(const string &targetSdk, Sdk &sdk) // 1) the first line contains the path to the Qt tools like qmake // 2) the second line contains the path to the Qt libraries // further lines are reserved for future enhancement +#if _POSIX_VERSION >= 200809L + size_t len = 0; + char *line = 0; + ssize_t read = getline(&line, &len, f); + if (read < 0) { + free(line); + fclose(f); + return false; + } + sdk.toolsPath = line; + + read = getline(&line, &len, f); + if (read < 0) { + free(line); + fclose(f); + return false; + } + sdk.librariesPath = line; + + free(line); +#elif defined(PATH_MAX) char buf[PATH_MAX]; if (!fgets(buf, PATH_MAX - 1, f)) { fclose(f); return false; } sdk.toolsPath = buf; - sdk.toolsPath.erase(sdk.toolsPath.size() - 1); // drop newline if (!fgets(buf, PATH_MAX - 1, f)) { fclose(f); return false; } sdk.librariesPath = buf; +#else +# error "POSIX < 2008 and no PATH_MAX, fix me" +#endif + sdk.toolsPath.erase(sdk.toolsPath.size() - 1); // drop newline sdk.librariesPath.erase(sdk.librariesPath.size() - 1); // drop newline fclose(f); |