00001 #include "utils_cl2.h" 00002 00003 #include "er_errors.h" 00004 00005 #include <glib/gprintf.h> 00006 #include <glib/gstdio.h> 00007 00008 #include <ctype.h> 00009 #include <errno.h> 00010 #include <string.h> 00011 00012 // See <asm-generic/errno-base.h> for some related "errno" values. 00013 00014 gboolean mkdir_p(const gchar* pathname, GError** error) 00015 { 00016 assert_error_unset(error); 00017 00018 if (strlen(pathname) == 0) 00019 return TRUE; 00020 00021 int hadErr; 00022 // This function may throw OOM. 00023 TRAP_OOM_FAIL(hadErr = g_mkdir_with_parents(pathname, 0777)); 00024 if (G_UNLIKELY(hadErr)) { 00025 if (error) 00026 *error = gx_error_new(G_FILE_ERROR, g_file_error_from_errno(errno), "error creating directory '%s': %s (%d)", pathname, strerror(errno), errno); 00027 return FALSE; 00028 } 00029 return TRUE; 00030 00031 #if defined(__SYMBIAN32__) 00032 fail: 00033 if (error) *error = gx_error_no_memory; 00034 return FALSE; 00035 #endif /* __SYMBIAN32__ */ 00036 } 00037 00038 gboolean rm_file(const gchar* pathname, GError** error) 00039 { 00040 assert_error_unset(error); 00041 // g_unlink is OOM safe on Symbian 00042 if (g_unlink(pathname)) { 00043 if (error) 00044 *error = gx_error_new(G_FILE_ERROR, g_file_error_from_errno(errno), "error deleting file '%s': %s (%d)", pathname, strerror(errno), errno); 00045 return FALSE; 00046 } 00047 return TRUE; 00048 } 00049 00050 #if !GLIB_CHECK_VERSION(2,14,6) 00051 // On Symbian, reports ENOMEM by throwing a GLib OOM error. 00052 void g_string_vprintf(GString *string, 00053 const gchar *format, 00054 va_list args) 00055 { 00056 gchar* buf; 00057 g_vasprintf(&buf, format, args); 00058 g_string_assign(string, buf); 00059 g_free(buf); 00060 } 00061 #endif 00062 00063 gboolean is_ascii_ident(const gchar* s) 00064 { 00065 if (!*s) return FALSE; 00066 // if (!isalpha(*s) && (*s != '_')) return FALSE; s++; // we want to allow an IMEI code as an ident 00067 while (*s) { 00068 if (!isalnum(*s) && (*s != '_')) return FALSE; 00069 s++; 00070 } 00071 return TRUE; 00072 } 00073 00074 /** 00075 00076 utils_cl2.c 00077 00078 Copyright 2009 Helsinki Institute for Information Technology (HIIT) 00079 and the authors. All rights reserved. 00080 00081 Authors: Tero Hasu <tero.hasu@hut.fi> 00082 00083 Permission is hereby granted, free of charge, to any person 00084 obtaining a copy of this software and associated documentation files 00085 (the "Software"), to deal in the Software without restriction, 00086 including without limitation the rights to use, copy, modify, merge, 00087 publish, distribute, sublicense, and/or sell copies of the Software, 00088 and to permit persons to whom the Software is furnished to do so, 00089 subject to the following conditions: 00090 00091 The above copyright notice and this permission notice shall be 00092 included in all copies or substantial portions of the Software. 00093 00094 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00095 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00096 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00097 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 00098 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 00099 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 00100 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 00101 SOFTWARE. 00102 00103 **/
ContextLogger2—ContextLogger2 Logger Daemon Internals—Generated on Mon May 2 13:49:57 2011 by Doxygen 1.6.1