Commit bc2e9dab authored by Kitware Robot's avatar Kitware Robot Committed by Brad King
Browse files

KWSys 2013-07-10 (beef6819)

Extract upstream KWSys using the following shell commands.

$ git archive --prefix=upstream-kwsys/ beef6819 | tar x
$ git shortlog --no-merges --abbrev=8 --format='%h %s' 5b0d1bd9..beef6819
Andreas Mohr (1):
      f4928d44 Fix spelling and typos in comments and method documentation

Brad King (7):
      5c34ed2e SystemTools: Do not abort with no current directory
      709fb5c1 SystemTools: Fix FileIsDirectory for Windows drive letter roots
      9fd64779 SystemTools: Fix FileIsDirectory with long paths
      e3370418 SystemTools: Use COMPILE_DEFINITIONS to pass platform tests
      dccf7725 SystemTools: Touch with better than 1s resolution if possible
      d79a792e SystemTools: Fix CollapseFullPath to not erase root component
      beef6819 SystemTools: Implement IsSubDirectory without loop

Cory Quammen (1):
      3d1d4e7c SystemTools: MakeDirectory() reports failure if path is file

Paul Kunysch (1):
      2d263bc3 Process: Increase FD_SETSIZE on Cygwin

Rolf Eike Beer (3):
      e8269442 Tests: fix a warning with acc
      87abd647 SystemInformation: fix truncation warnings
      039d9598 fix warnings about sizeof() return value truncation

Sean McBride (2):
      13f5badd SystemInformation: Replace __GNUG__ with __GNUC__
      f6c4c247 RegularExpression: Remove 'register' storage specifier

Change-Id: I25759bb9f579b7702314bce688cd989a409618e4
parent 3884678c
......@@ -569,8 +569,17 @@ IF(KWSYS_USE_SystemTools)
"Checking whether CXX compiler has unsetenv" DIRECT)
KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_ENVIRON_IN_STDLIB_H
"Checking whether CXX compiler has environ in stdlib.h" DIRECT)
SET_SOURCE_FILES_PROPERTIES(SystemTools.cxx PROPERTIES
COMPILE_FLAGS "-DKWSYS_CXX_HAS_SETENV=${KWSYS_CXX_HAS_SETENV} -DKWSYS_CXX_HAS_UNSETENV=${KWSYS_CXX_HAS_UNSETENV} -DKWSYS_CXX_HAS_ENVIRON_IN_STDLIB_H=${KWSYS_CXX_HAS_ENVIRON_IN_STDLIB_H}")
KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_UTIMES
"Checking whether CXX compiler has utimes" DIRECT)
KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_UTIMENSAT
"Checking whether CXX compiler has utimensat" DIRECT)
SET_PROPERTY(SOURCE SystemTools.cxx APPEND PROPERTY COMPILE_DEFINITIONS
KWSYS_CXX_HAS_SETENV=${KWSYS_CXX_HAS_SETENV}
KWSYS_CXX_HAS_UNSETENV=${KWSYS_CXX_HAS_UNSETENV}
KWSYS_CXX_HAS_ENVIRON_IN_STDLIB_H=${KWSYS_CXX_HAS_ENVIRON_IN_STDLIB_H}
KWSYS_CXX_HAS_UTIMES=${KWSYS_CXX_HAS_UTIMES}
KWSYS_CXX_HAS_UTIMENSAT=${KWSYS_CXX_HAS_UTIMENSAT}
)
ENDIF()
IF(KWSYS_USE_SystemInformation)
......
......@@ -44,7 +44,7 @@ struct CommandLineArgumentsCallbackStructure;
*
* For the variable interface you associate variable with each argument. When
* the argument is specified, the variable is set to the specified value casted
* to the apropriate type. For boolean (NO_ARGUMENT), the value is "1".
* to the appropriate type. For boolean (NO_ARGUMENT), the value is "1".
*
* Both interfaces can be used at the same time.
*
......@@ -99,7 +99,7 @@ public:
STRING_TYPE, // The variable is string (char*)
STL_STRING_TYPE, // The variable is string (char*)
VECTOR_INT_TYPE, // The variable is integer (int)
VECTOR_BOOL_TYPE, // The vairable is boolean (bool)
VECTOR_BOOL_TYPE, // The variable is boolean (bool)
VECTOR_DOUBLE_TYPE, // The variable is float (double)
VECTOR_STRING_TYPE, // The variable is string (char*)
VECTOR_STL_STRING_TYPE, // The variable is string (char*)
......@@ -128,7 +128,7 @@ public:
void ProcessArgument(const char* arg);
/**
* This method will parse arguments and call apropriate methods.
* This method will parse arguments and call appropriate methods.
*/
int Parse();
......@@ -144,7 +144,7 @@ public:
/**
* Add handler for argument which is going to set the variable to the
* specified value. If the argument is specified, the option is casted to the
* apropriate type.
* appropriate type.
*/
void AddArgument(const char* argument, ArgumentTypeEnum type,
bool* variable, const char* help);
......@@ -160,7 +160,7 @@ public:
/**
* Add handler for argument which is going to set the variable to the
* specified value. If the argument is specified, the option is casted to the
* apropriate type. This will handle the multi argument values.
* appropriate type. This will handle the multi argument values.
*/
void AddArgument(const char* argument, ArgumentTypeEnum type,
kwsys_stl::vector<bool>* variable, const char* help);
......
......@@ -47,6 +47,12 @@ do.
*/
#if defined(__CYGWIN__)
/* Increase the file descriptor limit for select() before including
related system headers. (Default: 64) */
# define FD_SETSIZE 16384
#endif
#include <stddef.h> /* ptrdiff_t */
#include <stdio.h> /* snprintf */
#include <stdlib.h> /* malloc, free */
......
......@@ -312,8 +312,8 @@ static char* regbranch (int*);
static char* regpiece (int*);
static char* regatom (int*);
static char* regnode (char);
static const char* regnext (register const char*);
static char* regnext (register char*);
static const char* regnext (const char*);
static char* regnext (char*);
static void regc (char);
static void reginsert (char, char*);
static void regtail (char*, const char*);
......@@ -344,10 +344,10 @@ static int strcspn ();
// for later pattern matching.
bool RegularExpression::compile (const char* exp) {
register const char* scan;
register const char* longest;
register size_t len;
int flags;
const char* scan;
const char* longest;
size_t len;
int flags;
if (exp == 0) {
//RAISE Error, SYM(RegularExpression), SYM(No_Expr),
......@@ -444,11 +444,11 @@ bool RegularExpression::compile (const char* exp) {
* follows makes it hard to avoid.
*/
static char* reg (int paren, int *flagp) {
register char* ret;
register char* br;
register char* ender;
register int parno =0;
int flags;
char* ret;
char* br;
char* ender;
int parno =0;
int flags;
*flagp = HASWIDTH; // Tentatively.
......@@ -525,10 +525,10 @@ static char* reg (int paren, int *flagp) {
* Implements the concatenation operator.
*/
static char* regbranch (int *flagp) {
register char* ret;
register char* chain;
register char* latest;
int flags;
char* ret;
char* chain;
char* latest;
int flags;
*flagp = WORST; // Tentatively.
......@@ -562,10 +562,10 @@ static char* regbranch (int *flagp) {
* endmarker role is not redundant.
*/
static char* regpiece (int *flagp) {
register char* ret;
register char op;
register char* next;
int flags;
char* ret;
char op;
char* next;
int flags;
ret = regatom(&flags);
if (ret == 0)
......@@ -631,8 +631,8 @@ static char* regpiece (int *flagp) {
* separate node; the code is simpler that way and it's not worth fixing.
*/
static char* regatom (int *flagp) {
register char* ret;
int flags;
char* ret;
int flags;
*flagp = WORST; // Tentatively.
......@@ -648,8 +648,8 @@ static char* regatom (int *flagp) {
*flagp |= HASWIDTH | SIMPLE;
break;
case '[':{
register int rxpclass;
register int rxpclassend;
int rxpclass;
int rxpclassend;
if (*regparse == '^') { // Complement of range.
ret = regnode(ANYBUT);
......@@ -720,8 +720,8 @@ static char* regatom (int *flagp) {
*flagp |= HASWIDTH | SIMPLE;
break;
default:{
register int len;
register char ender;
int len;
char ender;
regparse--;
len = int(strcspn(regparse, META));
......@@ -754,8 +754,8 @@ static char* regatom (int *flagp) {
Location.
*/
static char* regnode (char op) {
register char* ret;
register char* ptr;
char* ret;
char* ptr;
ret = regcode;
if (ret == &regdummy) {
......@@ -790,9 +790,9 @@ static void regc (char b) {
* Means relocating the operand.
*/
static void reginsert (char op, char* opnd) {
register char* src;
register char* dst;
register char* place;
char* src;
char* dst;
char* place;
if (regcode == &regdummy) {
regsize += 3;
......@@ -816,9 +816,9 @@ static void reginsert (char op, char* opnd) {
- regtail - set the next-pointer at the end of a node chain
*/
static void regtail (char* p, const char* val) {
register char* scan;
register char* temp;
register int offset;
char* scan;
char* temp;
int offset;
if (p == &regdummy)
return;
......@@ -893,7 +893,7 @@ bool RegularExpression::find (kwsys_stl::string const& s)
// Returns true if found, and sets start and end indexes accordingly.
bool RegularExpression::find (const char* string) {
register const char* s;
const char* s;
this->searchstring = string;
......@@ -956,9 +956,9 @@ bool RegularExpression::find (const char* string) {
*/
static int regtry (const char* string, const char* *start,
const char* *end, const char* prog) {
register int i;
register const char* *sp1;
register const char* *ep;
int i;
const char* *sp1;
const char* *ep;
reginput = string;
regstartp = start;
......@@ -992,8 +992,8 @@ static int regtry (const char* string, const char* *start,
* 0 failure, 1 success
*/
static int regmatch (const char* prog) {
register const char* scan; // Current node.
const char* next; // Next node.
const char* scan; // Current node.
const char* next; // Next node.
scan = prog;
......@@ -1016,8 +1016,8 @@ static int regmatch (const char* prog) {
reginput++;
break;
case EXACTLY:{
register size_t len;
register const char* opnd;
size_t len;
const char* opnd;
opnd = OPERAND(scan);
// Inline the first character, for speed.
......@@ -1052,8 +1052,8 @@ static int regmatch (const char* prog) {
case OPEN + 7:
case OPEN + 8:
case OPEN + 9:{
register int no;
register const char* save;
int no;
const char* save;
no = OP(scan) - OPEN;
save = reginput;
......@@ -1081,8 +1081,8 @@ static int regmatch (const char* prog) {
case CLOSE + 7:
case CLOSE + 8:
case CLOSE + 9:{
register int no;
register const char* save;
int no;
const char* save;
no = OP(scan) - CLOSE;
save = reginput;
......@@ -1103,7 +1103,7 @@ static int regmatch (const char* prog) {
// break;
case BRANCH:{
register const char* save;
const char* save;
if (OP(next) != BRANCH) // No choice.
next = OPERAND(scan); // Avoid recursion.
......@@ -1122,10 +1122,10 @@ static int regmatch (const char* prog) {
break;
case STAR:
case PLUS:{
register char nextch;
register int no;
register const char* save;
register int min_no;
char nextch;
int no;
const char* save;
int min_no;
//
// Lookahead to avoid useless match attempts when we know
......@@ -1174,9 +1174,9 @@ static int regmatch (const char* prog) {
- regrepeat - repeatedly match something simple, report how many
*/
static int regrepeat (const char* p) {
register int count = 0;
register const char* scan;
register const char* opnd;
int count = 0;
const char* scan;
const char* opnd;
scan = reginput;
opnd = OPERAND(p);
......@@ -1216,8 +1216,8 @@ static int regrepeat (const char* p) {
/*
- regnext - dig the "next" pointer out of a node
*/
static const char* regnext (register const char* p) {
register int offset;
static const char* regnext (const char* p) {
int offset;
if (p == &regdummy)
return (0);
......@@ -1232,8 +1232,8 @@ static const char* regnext (register const char* p) {
return (p + offset);
}
static char* regnext (register char* p) {
register int offset;
static char* regnext (char* p) {
int offset;
if (p == &regdummy)
return (0);
......
......@@ -772,7 +772,7 @@ static int kwsys_shared_forward_get_settings(const char* self_path,
const char** dir;
for(dir = search_path; *dir; ++dir)
{
/* Add seperator between path components. */
/* Add separator between path components. */
if(dir != search_path)
{
strcat(ldpath, kwsys_shared_forward_path_sep);
......
......@@ -130,7 +130,7 @@ typedef int siginfo_t;
# define KWSYS_SYSTEMINFORMATION_IMPLEMENT_FQDN
# endif
# endif
# if defined(__GNUG__)
# if defined(__GNUC__)
# include <execinfo.h>
# if !(defined(__LSB_VERSION__) && __LSB_VERSION__ < 41)
# define KWSYS_SYSTEMINFORMATION_HAVE_BACKTRACE
......@@ -1471,7 +1471,7 @@ int SystemInformationImplementation::GetFullyQualifiedDomainName(
{
char host[NI_MAXHOST]={'\0'};
int addrlen
socklen_t addrlen
= (fam==AF_INET?sizeof(struct sockaddr_in):sizeof(struct sockaddr_in6));
ierr=getnameinfo(
......@@ -3487,7 +3487,7 @@ bool SystemInformationImplementation::QueryLinuxMemory()
bool have[6] = { false, false, false, false, false, false };
unsigned long value[6];
int count = 0;
while(fgets(buffer, sizeof(buffer), fd))
while(fgets(buffer, static_cast<int>(sizeof(buffer)), fd))
{
for(int i=0; i < 6; ++i)
{
......
......@@ -117,8 +117,8 @@ public:
// Get total system RAM in units of KiB available to this process.
// This may differ from the host available if a per-process resource
// limit is applied. per-process memory limits are applied on unix
// system via rlimit api. Resource limits that are not imposed via
// rlimit api may be reported to us via an application specified
// system via rlimit API. Resource limits that are not imposed via
// rlimit API may be reported to us via an application specified
// environment variable.
LongLong GetProcMemoryAvailable(
const char *hostLimitEnvVarName=NULL,
......
......@@ -196,18 +196,16 @@ inline int Rmdir(const char* dir)
}
inline const char* Getcwd(char* buf, unsigned int len)
{
const char* ret = _getcwd(buf, len);
if(!ret)
if(const char* ret = _getcwd(buf, len))
{
fprintf(stderr, "No current working directory.\n");
abort();
}
// make sure the drive letter is capital
if(strlen(buf) > 1 && buf[1] == ':')
{
buf[0] = toupper(buf[0]);
// make sure the drive letter is capital
if(strlen(buf) > 1 && buf[1] == ':')
{
buf[0] = toupper(buf[0]);
}
return ret;
}
return ret;
return 0;
}
inline int Chdir(const char* dir)
{
......@@ -245,13 +243,7 @@ inline int Rmdir(const char* dir)
}
inline const char* Getcwd(char* buf, unsigned int len)
{
const char* ret = getcwd(buf, len);
if(!ret)
{
fprintf(stderr, "No current working directory\n");
abort();
}
return ret;
return getcwd(buf, len);
}
inline int Chdir(const char* dir)
......@@ -613,7 +605,7 @@ bool SystemTools::MakeDirectory(const char* path)
}
if(SystemTools::FileExists(path))
{
return true;
return SystemTools::FileIsDirectory(path);
}
kwsys_stl::string dir = path;
if(dir.size() == 0)
......@@ -1132,22 +1124,58 @@ bool SystemTools::Touch(const char* filename, bool create)
}
return false;
}
#ifdef _MSC_VER
#define utime _utime
#define utimbuf _utimbuf
#endif
struct stat fromStat;
if(stat(filename, &fromStat) < 0)
#if defined(_WIN32) && !defined(__CYGWIN__)
HANDLE h = CreateFile(filename, FILE_WRITE_ATTRIBUTES,
FILE_SHARE_WRITE, 0, OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS, 0);
if(!h)
{
return false;
}
FILETIME mtime;
GetSystemTimeAsFileTime(&mtime);
if(!SetFileTime(h, 0, 0, &mtime))
{
CloseHandle(h);
return false;
}
struct utimbuf buf;
buf.actime = fromStat.st_atime;
buf.modtime = static_cast<time_t>(SystemTools::GetTime());
if(utime(filename, &buf) < 0)
CloseHandle(h);
#elif KWSYS_CXX_HAS_UTIMENSAT
struct timespec times[2] = {{0,UTIME_OMIT},{0,UTIME_NOW}};
if(utimensat(AT_FDCWD, filename, times, 0) < 0)
{
return false;
}
#else
struct stat st;
if(stat(filename, &st) < 0)
{
return false;
}
struct timeval mtime;
gettimeofday(&mtime, 0);
# if KWSYS_CXX_HAS_UTIMES
struct timeval times[2] =
{
# if KWSYS_STAT_HAS_ST_MTIM
{st.st_atim.tv_sec, st.st_atim.tv_nsec/1000}, /* tv_sec, tv_usec */
# else
{st.st_atime, 0},
# endif
mtime
};
if(utimes(filename, times) < 0)
{
return false;
}
# else
struct utimbuf times = {st.st_atime, mtime.tv_sec};
if(utime(filename, &times) < 0)
{
return false;
}
# endif
#endif
return true;
}
......@@ -2749,15 +2777,24 @@ bool SystemTools::FileIsDirectory(const char* name)
return false;
}
// Remove any trailing slash from the name.
char buffer[KWSYS_SYSTEMTOOLS_MAXPATH];
// Remove any trailing slash from the name except in a root component.
char local_buffer[KWSYS_SYSTEMTOOLS_MAXPATH];
std::string string_buffer;
size_t last = length-1;
if(last > 0 && (name[last] == '/' || name[last] == '\\')
&& strcmp(name, "/") !=0)
&& strcmp(name, "/") !=0 && name[last-1] != ':')
{
memcpy(buffer, name, last);
buffer[last] = 0;
name = buffer;
if(last < sizeof(local_buffer))
{
memcpy(local_buffer, name, last);
local_buffer[last] = 0;
name = local_buffer;
}
else
{
string_buffer.append(name, last);
name = string_buffer.c_str();
}
}
// Now check the file node type.
......@@ -3048,7 +3085,7 @@ SystemToolsAppendComponents(
{
if(*i == "..")
{
if(out_components.begin() != out_components.end())
if(out_components.size() > 1)
{
out_components.erase(out_components.end()-1, out_components.end());
}
......@@ -3089,7 +3126,7 @@ kwsys_stl::string SystemTools::CollapseFullPath(const char* in_path,
}
else
{
// ??
base_components.push_back("");
}
}
......@@ -4010,7 +4047,7 @@ void SystemTools::SplitProgramFromArgs(const char* path,
args = dir.substr(spacePos, dir.size()-spacePos);
return;
}
// Now try and find the the program in the path
// Now try and find the program in the path
findProg = SystemTools::FindProgram(tryProg.c_str(), e);
if(findProg.size())
{
......@@ -4224,17 +4261,13 @@ bool SystemTools::IsSubDirectory(const char* cSubdir, const char* cDir)
}
kwsys_stl::string subdir = cSubdir;
kwsys_stl::string dir = cDir;
SystemTools::ConvertToUnixSlashes(subdir);
SystemTools::ConvertToUnixSlashes(dir);
kwsys_stl::string path = subdir;
do
if(subdir.size() > dir.size() && subdir[dir.size()] == '/')
{
path = SystemTools::GetParentDirectory(path.c_str());
if(SystemTools::ComparePath(dir.c_str(), path.c_str()))
{
return true;
}
std::string s = subdir.substr(0, dir.size());
return SystemTools::ComparePath(s.c_str(), dir.c_str());
}
while ( path.size() > dir.size() );
return false;
}
......
......@@ -766,7 +766,7 @@ public:
static kwsys_stl::string GetCurrentWorkingDirectory(bool collapse =true);
/**
* Change directory the the directory specified
* Change directory to the directory specified
*/
static int ChangeDirectory(const char* dir);
......
......@@ -494,6 +494,25 @@ int main()
}
#endif
#ifdef TEST_KWSYS_CXX_HAS_UTIMES
#include <sys/time.h>
int main()
{
struct timeval* current_time = 0;
return utimes("/example", current_time);
}
#endif
#ifdef TEST_KWSYS_CXX_HAS_UTIMENSAT
#include <fcntl.h>
#include <sys/stat.h>
int main()
{
struct timespec times[2] = {{0,UTIME_OMIT},{0,UTIME_NOW}};
return utimensat(AT_FDCWD, "/example", times, AT_SYMLINK_NOFOLLOW);
}
#endif
#ifdef TEST_KWSYS_CXX_TYPE_INFO
/* Collect fundamental type information and save it to a CMake script. */
......
......@@ -109,9 +109,9 @@ int testDynamicLoader(int argc, char *argv[])
// dlopen() on Syllable before 11/22/2007 doesn't return 0 on error
#ifndef __SYLLABLE__
// Make sure that inexistant lib is giving correct result
// Make sure that inexistent lib is giving correct result
res += TestDynamicLoader("azerty_", "foo_bar",0,0,0);
// Make sure that random binary file cannnot be assimilated as dylib
// Make sure that random binary file cannot be assimilated as dylib