diff options
| author | su_v <suv-sf@users.sourceforge.net> | 2012-12-16 05:41:25 +0000 |
|---|---|---|
| committer | ~suv <suv-sf@users.sourceforge.net> | 2012-12-16 05:41:25 +0000 |
| commit | 7ec903c9898f872dbd9426ed7a62e1969fdb7be7 (patch) | |
| tree | a306139e829118a83516af02279c9eafd3440eaa /src/io | |
| parent | Hershey Text: whitespace; py: docstring, modeline; inx: fix attribute value (diff) | |
| parent | Translations.Spanish translation update by Lucas Vieites. (diff) | |
| download | inkscape-7ec903c9898f872dbd9426ed7a62e1969fdb7be7.tar.gz inkscape-7ec903c9898f872dbd9426ed7a62e1969fdb7be7.zip | |
merge from trunk (r11955)
(bzr r11687.1.3)
Diffstat (limited to 'src/io')
| -rw-r--r-- | src/io/ftos.cpp | 4 | ||||
| -rw-r--r-- | src/io/sys.cpp | 34 | ||||
| -rw-r--r-- | src/io/sys.h | 2 |
3 files changed, 38 insertions, 2 deletions
diff --git a/src/io/ftos.cpp b/src/io/ftos.cpp index 658c768e8..d0764d86c 100644 --- a/src/io/ftos.cpp +++ b/src/io/ftos.cpp @@ -172,7 +172,7 @@ using namespace std; // This routine counts from the end of a string like '10229000' to find the index // of the first non-'0' character (5 would be returned for the above number.) -int countDigs(char *p) +static int countDigs(char *p) { int length =0; while (*(p+length)!='\0') length++; // Count total length @@ -186,7 +186,7 @@ int countDigs(char *p) // is between 0 and 1. Returns 1 if v==0. Return value is positive for numbers // greater than or equal to 1, negative for numbers less than 0.1, and zero for // numbers between 0.1 and 1. -int countLhsDigits(double v) +static int countLhsDigits(double v) { if (v<0) v = -v; // Take abs value else if (v==0) return 1; // Special case if v==0 diff --git a/src/io/sys.cpp b/src/io/sys.cpp index 5f19ee5db..26c1993a7 100644 --- a/src/io/sys.cpp +++ b/src/io/sys.cpp @@ -239,6 +239,40 @@ bool Inkscape::IO::file_is_writable( char const *utf8name) return success; } +/**Checks if directory of file exists, useful + * because inkscape doesn't create directories.*/ +bool Inkscape::IO::file_directory_exists( char const *utf8name ){ + bool exists = true; + + if ( utf8name) { + gchar *filename = NULL; + if (utf8name && !g_utf8_validate(utf8name, -1, NULL)) { + /* FIXME: Trying to guess whether or not a filename is already in utf8 is unreliable. + If any callers pass non-utf8 data (e.g. using g_get_home_dir), then change caller to + use simple g_file_test. Then add g_return_val_if_fail(g_utf_validate(...), false) + to beginning of this function. */ + filename = g_strdup(utf8name); + // Looks like g_get_home_dir isn't safe. + //g_warning("invalid UTF-8 detected internally. HUNT IT DOWN AND KILL IT!!!"); + } else { + filename = g_filename_from_utf8 ( utf8name, -1, NULL, NULL, NULL ); + } + if ( filename ) { + gchar *dirname = g_path_get_dirname(filename); + exists = Inkscape::IO::file_test( dirname, G_FILE_TEST_EXISTS); + g_free(filename); + g_free(dirname); + filename = NULL; + dirname = NULL; + } else { + g_warning( "Unable to convert filename in IO:file_test" ); + } + } + + return exists; + +} + /** Wrapper around g_dir_open, but taking a utf8name as first argument. */ GDir * Inkscape::IO::dir_open(gchar const *const utf8name, guint const flags, GError **const error) diff --git a/src/io/sys.h b/src/io/sys.h index fbfe4d4c4..78d25afa3 100644 --- a/src/io/sys.h +++ b/src/io/sys.h @@ -36,6 +36,8 @@ int file_open_tmp( std::string& name_used, const std::string& prefix ); bool file_test( char const *utf8name, GFileTest test ); +bool file_directory_exists( char const *utf8name ); + bool file_is_writable( char const *utf8name); GDir *dir_open(gchar const *utf8name, guint flags, GError **error); |
