switch-coreboot/util/lar/lib.c
Stefan Reinauer 92efb61fa7 Add initial version of lar to the archive.
Signed-off-by: Stefan Reinauer <stepan@coresystems.de>
Acked-By: Stefan Reinauer  <stepan@coresystems.de> and others.


git-svn-id: svn://coreboot.org/repository/LinuxBIOSv3@39 f3766cd6-281f-0410-b1cd-43a5c92072e9
2006-11-07 17:32:43 +00:00

75 lines
1.7 KiB
C

/*
* lar - linuxbios archiver
*
* written by Stefan Reinauer <stepan@coresystems.de>
*
* (C) 2006 coresystems GmbH. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
int mkdirp(char *dirpath)
{
#define MAX_PATH 1024
char *pos, *currpath, *path;
char cwd[MAX_PATH];
int ret=0;
path = strdup(dirpath);
currpath = path;
if(!getcwd(cwd, MAX_PATH)) {
free(path);
printf("error getting cwd\n");
return -1;
}
do {
pos=index(currpath,'/');
if (pos)*pos=0;
//printf("cp=%s\n",currpath);
mkdir(currpath,0755);
ret=chdir(currpath);
if(pos) currpath=pos+1;
} while (pos && !ret && strlen(currpath)) ;
chdir(cwd);
free(path);
return ret;
}
#if 0
int main(void) {
int ret;
ret=mkdirp("a/b/c/d/");
if (ret) printf("error! mkdir\n\n");
else printf("jippie! mkdir\n\n");
ret=mkdirp("a/b/c/d");
if (ret) printf("error! mkdir\n");
else printf("jippie! mkdir\n");
return 0;
}
#endif