libc.obj:
- Added basename() and dirname() - libc_test all tabs -> spaces git-svn-id: svn://kolibrios.org@9262 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
1b84dbe19e
commit
9257d2c34c
Binary file not shown.
7
programs/develop/ktcc/trunk/libc.obj/include/libgen.h
Normal file
7
programs/develop/ktcc/trunk/libc.obj/include/libgen.h
Normal file
@ -0,0 +1,7 @@
|
||||
#ifndef _LIBGEN_H_
|
||||
#define _LIBGEN_H_
|
||||
|
||||
extern char* _FUNC(dirname)(char *);
|
||||
extern char* _FUNC(basename)(char *);
|
||||
|
||||
#endif
|
@ -1,7 +1,9 @@
|
||||
#include <sys/ksys.h>
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
int comp(void *a, void *b) {
|
||||
return *(int*)a - *(int*)b;
|
||||
@ -68,8 +70,6 @@ int main(){
|
||||
assert(strtod(start, &end) == 100.0);
|
||||
assert(!strcmp(end, " Rub"));
|
||||
|
||||
// rand ¨ srand ¯à®¢¥à¥ë ¢àãçãî :3
|
||||
|
||||
char *st3 = "21.3e3Hello World!";
|
||||
assert(atof(st3) == 21300.0);
|
||||
|
||||
@ -79,6 +79,10 @@ int main(){
|
||||
assert(nums[i] == i);
|
||||
}
|
||||
|
||||
time_t libc_time = time(NULL);
|
||||
struct tm *libc_tm = localtime(&libc_time);
|
||||
printf(asctime(libc_tm));
|
||||
|
||||
puts("End testing.");
|
||||
exit(0);
|
||||
}
|
@ -116,6 +116,9 @@
|
||||
#include "time/time.c"
|
||||
#include "time/asctime.c"
|
||||
|
||||
#include "misc/basename.c"
|
||||
#include "misc/dirname.c"
|
||||
|
||||
__asm__(
|
||||
".include \"math/acos.s\"\n\t"
|
||||
".include \"math/asin.s\"\n\t"
|
||||
|
13
programs/develop/ktcc/trunk/libc.obj/source/misc/basename.c
Normal file
13
programs/develop/ktcc/trunk/libc.obj/source/misc/basename.c
Normal file
@ -0,0 +1,13 @@
|
||||
#include <string.h>
|
||||
#include <libgen.h>
|
||||
|
||||
char *basename(char *s)
|
||||
{
|
||||
size_t i;
|
||||
if (!s || !*s) return ".";
|
||||
i = strlen(s)-1;
|
||||
for (; i&&s[i]=='/'; i--) s[i] = 0;
|
||||
for (; i&&s[i-1]!='/'; i--);
|
||||
return s+i;
|
||||
}
|
||||
|
14
programs/develop/ktcc/trunk/libc.obj/source/misc/dirname.c
Normal file
14
programs/develop/ktcc/trunk/libc.obj/source/misc/dirname.c
Normal file
@ -0,0 +1,14 @@
|
||||
#include <string.h>
|
||||
#include <libgen.h>
|
||||
|
||||
char *dirname(char *s)
|
||||
{
|
||||
size_t i;
|
||||
if (!s || !*s) return ".";
|
||||
i = strlen(s)-1;
|
||||
for (; s[i]=='/'; i--) if (!i) return "/";
|
||||
for (; s[i]!='/'; i--) if (!i) return ".";
|
||||
for (; s[i]=='/'; i--) if (!i) return "/";
|
||||
s[i+1] = 0;
|
||||
return s;
|
||||
}
|
@ -172,3 +172,6 @@ time
|
||||
localtime
|
||||
asctime
|
||||
difftime
|
||||
!____MISC____
|
||||
basename
|
||||
dirname
|
||||
|
Loading…
Reference in New Issue
Block a user