aboutsummaryrefslogtreecommitdiffstats
path: root/android/utils
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-03-03 14:04:15 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2009-03-03 14:04:15 -0800
commitbae1bc39312d5019bd9a5b8d840a529213a69a17 (patch)
treeaed2580b00553aa307704f44050708f29bf3ac66 /android/utils
parentee2298a313b6e425d6ff0324be6a313b1cd9a399 (diff)
downloadexternal_qemu-bae1bc39312d5019bd9a5b8d840a529213a69a17.zip
external_qemu-bae1bc39312d5019bd9a5b8d840a529213a69a17.tar.gz
external_qemu-bae1bc39312d5019bd9a5b8d840a529213a69a17.tar.bz2
auto import from //depot/cupcake/@132589
Diffstat (limited to 'android/utils')
-rw-r--r--android/utils/ini.c42
-rw-r--r--android/utils/ini.h5
-rw-r--r--android/utils/path.c129
-rw-r--r--android/utils/path.h30
4 files changed, 6 insertions, 200 deletions
diff --git a/android/utils/ini.c b/android/utils/ini.c
index 95bb4e3..56e40f2 100644
--- a/android/utils/ini.c
+++ b/android/utils/ini.c
@@ -17,7 +17,6 @@
#include <errno.h>
#include "android/utils/debug.h"
#include "android/utils/system.h" /* for ASTRDUP */
-#include "android/utils/bufprint.h"
#include "osdep.h"
/* W() is used to print warnings, D() to print debugging info */
@@ -173,7 +172,7 @@ iniFile_newFromMemory( const char* text, const char* fileName )
int lineno = 0;
if (!fileName)
- fileName = "<memoryFile>";
+ fileName = "<unknownFile>";
D("%s: parsing as .ini file", fileName);
@@ -198,8 +197,8 @@ iniFile_newFromMemory( const char* text, const char* fileName )
key = p++;
if (!isKeyStartChar(*key)) {
p = skipToEOL(p);
- W("%4d: key name doesn't start with valid character. line ignored",
- lineno);
+ W("%s:%d: key name doesn't start with valid character. line ignored",
+ fileName, lineno);
continue;
}
@@ -211,8 +210,8 @@ iniFile_newFromMemory( const char* text, const char* fileName )
/* check the equal */
if (*p != '=') {
- W("%4d: missing expected assignment operator (=). line ignored",
- lineno);
+ W("%s:%d: missing expected assignment operator (=). line ignored",
+ fileName, lineno);
p = skipToEOL(p);
continue;
}
@@ -233,14 +232,12 @@ iniFile_newFromMemory( const char* text, const char* fileName )
valueLen = p - value;
iniFile_addPair(ini, key, keyLen, value, valueLen);
- D("%4d: KEY='%.*s' VALUE='%.*s'", lineno,
+ D("%s:%d: KEY='%.*s' VALUE='%.*s'", fileName, lineno,
keyLen, key, valueLen, value);
p = skipToEOL(p);
}
- D("%s: parsing finished", fileName);
-
return ini;
}
@@ -286,33 +283,6 @@ EXIT:
return ini;
}
-int
-iniFile_saveToFile( IniFile* f, const char* filepath )
-{
- FILE* fp = fopen(filepath, "wt");
- IniPair* pair = f->pairs;
- IniPair* pairEnd = pair + f->numPairs;
- int result = 0;
-
- if (fp == NULL) {
- D("could not create .ini file: %s: %s",
- filepath, strerror(errno));
- return -1;
- }
-
- for ( ; pair < pairEnd; pair++ ) {
- char temp[PATH_MAX], *p=temp, *end=p+sizeof(temp);
- p = bufprint(temp, end, "%s = %s\n", pair->key, pair->value);
- if (fwrite(temp, p - temp, 1, fp) != 1) {
- result = -1;
- break;
- }
- }
-
- fclose(fp);
- return result;
-}
-
char*
iniFile_getString( IniFile* f, const char* key )
{
diff --git a/android/utils/ini.h b/android/utils/ini.h
index a176bfe..bc8193e 100644
--- a/android/utils/ini.h
+++ b/android/utils/ini.h
@@ -62,11 +62,6 @@ IniFile* iniFile_newFromMemory( const char* text, const char* fileName );
*/
IniFile* iniFile_newFromFile( const char* filePath);
-/* try to write an IniFile into a given file.
- * returns 0 on success, -1 on error (see errno for error code)
- */
-int iniFile_saveToFile( IniFile* f, const char* filePath );
-
/* free an IniFile object */
void iniFile_free( IniFile* f );
diff --git a/android/utils/path.c b/android/utils/path.c
index b15b6de..9dd238e 100644
--- a/android/utils/path.c
+++ b/android/utils/path.c
@@ -101,111 +101,6 @@ path_parent( const char* path, int levels )
return result;
}
-static char*
-substring_dup( const char* start, const char* end )
-{
- int len = end - start;
- char* result = android_alloc(len+1);
- memcpy(result, start, len);
- result[len] = 0;
- return result;
-}
-
-int
-path_split( const char* path, char* *pdirname, char* *pbasename )
-{
- const char* end = path + strlen(path);
- const char* last;
- char* basename;
-
- /* prepare for errors */
- if (pdirname)
- *pdirname = NULL;
- if (pbasename)
- *pbasename = NULL;
-
- /* handle empty path case */
- if (end == path) {
- return -1;
- }
-
- /* strip trailing path separators */
- while (end > path && ispathsep(end[-1]))
- end -= 1;
-
- /* handle "/" and degenerate cases like "////" */
- if (end == path) {
- return -1;
- }
-
- /* find last separator */
- last = end;
- while (last > path && !ispathsep(last[-1]))
- last -= 1;
-
- /* handle cases where there is no path separator */
- if (last == path) {
- if (pdirname)
- *pdirname = ASTRDUP(".");
- if (pbasename)
- *pbasename = substring_dup(path,end);
- return 0;
- }
-
- /* handle "/foo" */
- if (last == path+1) {
- if (pdirname)
- *pdirname = ASTRDUP("/");
- if (pbasename)
- *pbasename = substring_dup(path+1,end);
- return 0;
- }
-
- /* compute basename */
- basename = substring_dup(last,end);
- if (strcmp(basename, ".") == 0 || strcmp(basename, "..") == 0) {
- AFREE(basename);
- return -1;
- }
-
- if (pbasename)
- *pbasename = basename;
- else {
- AFREE(basename);
- }
-
- /* compute dirname */
- if (pdirname != NULL)
- *pdirname = substring_dup(path,last-1);
-
- return 0;
-}
-
-char*
-path_basename( const char* path )
-{
- char* basename;
-
- if (path_split(path, NULL, &basename) < 0)
- return NULL;
-
- return basename;
-}
-
-char*
-path_dirname( const char* path )
-{
- char* dirname;
-
- if (path_split(path, &dirname, NULL) < 0)
- return NULL;
-
- return dirname;
-}
-
-
-
-
/** MISC FILE AND DIRECTORY HANDLING
**/
@@ -395,30 +290,6 @@ path_get_size( const char* path, uint64_t *psize )
}
-ABool
-path_is_absolute( const char* path )
-{
-#ifdef _WIN32
- if (path == NULL)
- return 0;
-
- if (path[0] == '/' || path[0] == '\\')
- return 1;
-
- /* 'C:' is always considered to be absolute
- * even if used with a relative path like C:foo which
- * is different from C:\foo
- */
- if (path[0] != 0 && path[1] == ':')
- return 1;
-
- return 0;
-#else
- return (path != NULL && path[0] == '/');
-#endif
-}
-
-
/** OTHER FILE UTILITIES
**
** path_empty_file() creates an empty file at a given path location.
diff --git a/android/utils/path.h b/android/utils/path.h
index e822834..10436c6 100644
--- a/android/utils/path.h
+++ b/android/utils/path.h
@@ -55,9 +55,6 @@ extern ABool path_is_regular( const char* path );
/* checks that a path points to a directory */
extern ABool path_is_dir( const char* path );
-/* checks that a path is absolute or not */
-extern ABool path_is_absolute( const char* path );
-
/* checks that one can read/write a given (regular) file */
extern ABool path_can_read( const char* path );
extern ABool path_can_write( const char* path );
@@ -80,33 +77,6 @@ extern APosixStatus path_get_size( const char* path, uint64_t *psize );
*/
extern char* path_parent( const char* path, int levels );
-/* split a path into a (dirname,basename) pair. the result strings must be freed
- * by the caller. Return 0 on success, or -1 on error. Error conditions include
- * the following:
- * - 'path' is empty
- * - 'path' is "/" or degenerate cases like "////"
- * - basename is "." or ".."
- *
- * if there is no directory separator in path, *dirname will be set to "."
- * if the path is of type "/foo", then *dirname will be set to "/"
- *
- * pdirname can be NULL if you don't want the directory name
- * pbasename can be NULL if you don't want the base name
- */
-extern int path_split( const char* path, char* *pdirname, char* *pbasename );
-
-/* a convenience function to retrieve the directory name as returned by
- * path_split(). Returns NULL if path_split() returns an error.
- * the result string must be freed by the caller
- */
-extern char* path_dirname( const char* path );
-
-/* a convenience function to retrieve the base name as returned by
- * path_split(). Returns NULL if path_split() returns an error.
- * the result must be freed by the caller.
- */
-extern char* path_basename( const char* path );
-
/** OTHER FILE UTILITIES
**
** path_empty_file() creates an empty file at a given path location.