]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/tools/toolutil/toolutil.c
ICU-400.42.tar.gz
[apple/icu.git] / icuSources / tools / toolutil / toolutil.c
index 8703445cc2108e516aadb66e84ba05f8686464c7..071eac7f57cb9f3eeb513a3213878177a90c7cc4 100644 (file)
@@ -1,7 +1,7 @@
 /*
 *******************************************************************************
 *
-*   Copyright (C) 1999-2004, International Business Machines
+*   Copyright (C) 1999-2008, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *
 *******************************************************************************
 *   This file contains utility functions for ICU tools like genccode.
 */
 
-#ifdef WIN32
+#include <stdio.h>
+#include "unicode/utypes.h"
+#include "unicode/putil.h"
+#include "cmemory.h"
+#include "cstring.h"
+#include "toolutil.h"
+#include "unicode/ucal.h"
+
+#ifdef U_WINDOWS
 #   define VC_EXTRALEAN
 #   define WIN32_LEAN_AND_MEAN
 #   define NOUSER
 #   define NOIME
 #   define NOMCX
 #   include <windows.h>
+#   include <direct.h>
+#else
+#   include <sys/stat.h>
+#   include <sys/types.h>
 #endif
-#include <stdio.h>
-#include "unicode/utypes.h"
-#include "unicode/putil.h"
-#include "cmemory.h"
-#include "cstring.h"
-#include "toolutil.h"
+#include <errno.h>
+
+static int32_t currentYear = -1;
+
+U_CAPI int32_t U_EXPORT2 getCurrentYear() {
+#if !UCONFIG_NO_FORMATTING
+    UErrorCode status=U_ZERO_ERROR;    
+    UCalendar *cal = NULL;
+
+    if(currentYear == -1) {
+        cal = ucal_open(NULL, -1, NULL, UCAL_TRADITIONAL, &status);
+        ucal_setMillis(cal, ucal_getNow(), &status);
+        currentYear = ucal_get(cal, UCAL_YEAR, &status);
+        ucal_close(cal);
+    }
+    return currentYear;
+#else
+    return 2008;
+#endif
+}
+
 
 U_CAPI const char * U_EXPORT2
 getLongPathname(const char *pathname) {
-#ifdef WIN32
+#ifdef U_WINDOWS
     /* anticipate problems with "short" pathnames */
     static WIN32_FIND_DATA info;
-    HANDLE file=FindFirstFile(pathname, &info);
+    HANDLE file=FindFirstFileA(pathname, &info);
     if(file!=INVALID_HANDLE_VALUE) {
         if(info.cAlternateFileName[0]!=0) {
             /* this file has a short name, get and use the long one */
@@ -75,6 +102,19 @@ findBasename(const char *filename) {
     }
 }
 
+U_CAPI void U_EXPORT2
+uprv_mkdir(const char *pathname, UErrorCode *status) {
+    int retVal = 0;
+#if defined(U_WINDOWS)
+    retVal = _mkdir(pathname);
+#else
+    retVal = mkdir(pathname, S_IRWXU | (S_IROTH | S_IXOTH) | (S_IROTH | S_IXOTH));
+#endif
+    if (retVal && errno != EEXIST) {
+        *status = U_FILE_ACCESS_ERROR;
+    }
+}
+
 /* tool memory helper ------------------------------------------------------- */
 
 struct UToolMemory {