You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
854 B
C
48 lines
854 B
C
#define _GNU_SOURCE
|
|
#include "format.h"
|
|
|
|
#include <stdarg.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <sys/stat.h>
|
|
|
|
const char* format( char* buffer, int size, const char* f, ... )
|
|
{
|
|
va_list args;
|
|
va_start(args,f);
|
|
vsnprintf( buffer, size, f, args );
|
|
va_end(args);
|
|
|
|
return buffer;
|
|
}
|
|
char* aformat( const char* f, ... )
|
|
{
|
|
va_list args;
|
|
va_start(args,f);
|
|
char* res = NULL;
|
|
vasprintf( &res, f, args );
|
|
va_end(args);
|
|
|
|
return res;
|
|
}
|
|
|
|
char* safe_strdup( const char* str )
|
|
{
|
|
if( !str ) { return NULL; }
|
|
return strdup(str);
|
|
}
|
|
|
|
void mkdir_p( const char* ch, int mode )
|
|
{
|
|
char buffer[512];
|
|
strncpy(buffer,ch,512);
|
|
char* rem = NULL;
|
|
char next_create[512] = "";
|
|
for( char* iter = strtok_r(buffer,"/",&rem); iter; iter = strtok_r(NULL,"/",&rem) ) {
|
|
strcat(next_create,iter);
|
|
mkdir( next_create, mode );
|
|
strcat(next_create,"/");
|
|
}
|
|
}
|
|
|