]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/tools/toolutil/filetools.cpp
ICU-62123.0.1.tar.gz
[apple/icu.git] / icuSources / tools / toolutil / filetools.cpp
index 058a6f7ccb3f8aeaf5cac9c041153fc428482ff5..176a791b0df853040d6c4291a01dbebb5b3cf79f 100644 (file)
@@ -1,13 +1,25 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
 /******************************************************************************
 /******************************************************************************
- *   Copyright (C) 2009, International Business Machines
+ *   Copyright (C) 2009-2013, International Business Machines
  *   Corporation and others.  All Rights Reserved.
  *******************************************************************************
  */
 
  *   Corporation and others.  All Rights Reserved.
  *******************************************************************************
  */
 
+#include "unicode/platform.h"
+#if U_PLATFORM == U_PF_MINGW
+// *cough* - for struct stat
+#ifdef __STRICT_ANSI__
+#undef __STRICT_ANSI__
+#endif
+#endif
+
 #include "filetools.h"
 #include "filestrm.h"
 #include "filetools.h"
 #include "filestrm.h"
+#include "charstr.h"
 #include "cstring.h"
 #include "unicode/putil.h"
 #include "cstring.h"
 #include "unicode/putil.h"
+#include "putilimp.h"
 
 #include <stdio.h>
 #include <stdlib.h>
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -19,8 +31,6 @@
 #include <dirent.h>
 typedef struct dirent DIRENT;
 
 #include <dirent.h>
 typedef struct dirent DIRENT;
 
-#define MAX_PATH_SIZE 4096 /* Set the limit for the size of the path. */
-
 #define SKIP1 "."
 #define SKIP2 ".."
 #endif
 #define SKIP1 "."
 #define SKIP2 ".."
 #endif
@@ -48,20 +58,24 @@ isFileModTimeLater(const char *filePath, const char *checkAgainst, UBool isDir)
 
             while ((dirEntry = readdir(pDir)) != NULL) {
                 if (uprv_strcmp(dirEntry->d_name, SKIP1) != 0 && uprv_strcmp(dirEntry->d_name, SKIP2) != 0) {
 
             while ((dirEntry = readdir(pDir)) != NULL) {
                 if (uprv_strcmp(dirEntry->d_name, SKIP1) != 0 && uprv_strcmp(dirEntry->d_name, SKIP2) != 0) {
-                    char newpath[MAX_PATH_SIZE] = "";
-                    uprv_strcpy(newpath, checkAgainst);
-                    uprv_strcat(newpath, U_FILE_SEP_STRING);
-                    uprv_strcat(newpath, dirEntry->d_name);
-
-                    if ((subDirp = opendir(newpath)) != NULL) {
+                    UErrorCode status = U_ZERO_ERROR;
+                    icu::CharString newpath(checkAgainst, -1, status);
+                    newpath.append(U_FILE_SEP_STRING, -1, status);
+                    newpath.append(dirEntry->d_name, -1, status);
+                    if (U_FAILURE(status)) {
+                        fprintf(stderr, "%s:%d: %s\n", __FILE__, __LINE__, u_errorName(status));
+                        return FALSE;
+                    };
+
+                    if ((subDirp = opendir(newpath.data())) != NULL) {
                         /* If this new path is a directory, make a recursive call with the newpath. */
                         closedir(subDirp);
                         /* If this new path is a directory, make a recursive call with the newpath. */
                         closedir(subDirp);
-                        isLatest = isFileModTimeLater(filePath, newpath, isDir);
+                        isLatest = isFileModTimeLater(filePath, newpath.data(), isDir);
                         if (!isLatest) {
                             break;
                         }
                     } else {
                         if (!isLatest) {
                             break;
                         }
                     } else {
-                        int32_t latest = whichFileModTimeIsLater(filePath, newpath);
+                        int32_t latest = whichFileModTimeIsLater(filePath, newpath.data());
                         if (latest < 0 || latest == 2) {
                             isLatest = FALSE;
                             break;
                         if (latest < 0 || latest == 2) {
                             isLatest = FALSE;
                             break;