Exemplo n.º 1
0
char * om_string_implode(om_list_ptr list, const char sep) {

	int items = om_list_count(list);
	char separ[] = {sep,'\0'};
	char *ret=OM_NULL;
	char *t=OM_NULL;
	
	for( int i=0; i<items; i++ ) {
		char *ptr = om_string_copy( om_list_get(list,i) );
		
		if(ret==OM_NULL) {
			ret=ptr;
		} else {
			t=ret;
			ret = om_string_append(t,ptr);
			om_free(t);
            om_free(ptr);
			if( ret==OM_NULL ) {
				return OM_NULL;
            }
		}
		
		if( i<items-1 ) {
			t=ret;
			ret = om_string_append(t,separ);
			om_free(t);
			if( ret==OM_NULL ) {
				return OM_NULL;
            }
		}
	}
	

	return ret;
}
Exemplo n.º 2
0
int __om_unzip_makedir (om_unzip_archive_ptr archive, const char *rootExportPath, char *newdir) {
	
	char *buffer = om_string_copy(newdir);
	if( buffer==OM_NULL ) {
		return UNZ_INTERNALERROR;
	}
	char *p;
	int len = (int)strlen(newdir);
	
	if (len <= 0)
		return 0;
	
	// prefix with the location where we want to create the dir structure
	if( buffer[0]==OM_FS_FILE_SEP ) {
		p = om_string_append(rootExportPath,buffer);
	} else {
		p = om_string_format("%s%c%s",rootExportPath,OM_FS_FILE_SEP,buffer);
	}
	om_free(buffer);
	buffer = p;
	p = OM_NULL;
	
	// if the path ended with a '/',
	// then take that off
	if (buffer[len-1] == '/') {
		buffer[len-1] = '\0';
	}
	if (__om_unzip_mymkdir(archive,buffer) == 0) {
		om_free(buffer);
		return 1;
    }
	
	p = buffer+1;
	while (1) {
		char hold;
		
		// we shouldn't need to create the rootExportPath
		if( strcmp(rootExportPath,buffer)==0 )
			break;
		
		while(*p && *p != '\\' && *p != '/')
			p++;
		hold = *p;
		*p = 0;
		if ( (__om_unzip_mymkdir(archive,buffer) == -1) && (errno == ENOENT) ) {
			__om_unzip_append_error(archive,om_string_format("couldn't create directory %s\n",buffer));
			om_free(buffer);
			return 0;
        }
		if ( hold == 0 )
			break;
		*p++ = hold;
    }
	om_free(buffer);
	return 1;
}