The time now is Fri 24 May 2013, 02:32
All times are UTC - 4 |
|
Page 2 of 2 [22 Posts] |
Goto page: Previous 1, 2 |
| Author |
Message |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Thu 06 Dec 2012, 00:33 Post subject:
|
|
just need to figure out how to deal with blah-0041.2 and blah-041.1
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
Ibidem
Joined: 25 May 2010 Posts: 248
|
Posted: Thu 06 Dec 2012, 19:24 Post subject:
|
|
| technosaurus wrote: | | just need to figure out how to deal with blah-0041.2 and blah-041.1 |
If you look in the manpage, that isn't ambiguous: numbers starting with 0 are considered to have an implied decimal point before the first 0, so the more leading zeros, the smaller.
Since it diverges at 00 vs 04, anything after the decimal point is ignored.
But there is another bug in the version I just posted:
compare 2004 204, and my code assumes it's dealing with a leading 0
I have an idea for fixing it, but haven't done so yet.
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Wed 30 Jan 2013, 03:58 Post subject:
|
|
simple qsort example, takes all arguments and prints sorted tab separated list
| Code: | #include <string.h>
static inline int cmp(const void *a, const void *b){
return strcmp(*(const char **)a, *(const char **)b);
}
int main(int argc, char *argv[]){
qsort(++argv, --argc, sizeof(char *), cmp);
while (argc){
write(1,argv[0],strlen(argv[0]));
write(1,(--argc && argv++)?"\t":"\n",1);
}
} |
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Thu 07 Feb 2013, 00:07 Post subject:
|
|
a faster (but bigger) strlen -needs work (misses \0 on multiples of
| Code: | size_t strlen(char *s){
size_t *v,ret;
v=(size_t *)s;
while (!(~((((*v & 0x7F7F7F7F) + 0x7F7F7F7F) | *v) | 0x7F7F7F7F))) v++; /*64bit size_t?*/
ret=(char *)v-s;
while (s[++ret]);
return ret;
} |
notes: need to use an unsigned int or 0 is 111111111111.....
maybe use:
((*v>>24)&&(*v&0xFF00FFFF))&&((*v&0xFFFF00FF)&&(*v<<24))
because the compiler can combine some of these operations and/or thread them
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Sat 16 Feb 2013, 18:04 Post subject:
|
|
here is a one-liner to generate macros for 300+ syscalls
| Code: | grep __NR_ unistd_32.h |awk '
{print "#define " substr($2,6,length($2)) "(...) syscall(" $2 ", __VA_ARGS__ )"}
' | sort > syscalls.h |
and now you have a 0kb c "library"
Note: zero-arg functions like fork() may need to be modified on older compilers and all of the types (structs, etc...) will need to be defined and there is absolutely no type checking. If you would like some semblance of type checking, you can later modify the defines to be static inline functions like:
| Code: | static inline long mycall(int a, char *b, struct somestruct c){
return syscall(__NR_mycall, a, b, c);
} |
There are quite a few other functions in the kernel that would be useful if you wanted to wrap them in a syscall for userspace (all of the crypto stuff and filesystem detection for instance)
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Sun 17 Feb 2013, 23:20 Post subject:
|
|
still working on syscalls. Here is a wacked out macro that redefines syscall() based on the number of args.
| Code: | #define NARGS(...) NARGS_(__VA_ARGS__, 6, 5, 4, 3, 2, 1, 0)(__VA_ARGS__)
#define NARGS_(dummy, n1, n2, n3, n4, n5, n6, n, ...) syscall##n
#define syscall(...) NARGS(__VA_ARGS__) |
thus syscall(__NR_mycall) becomes syscall0(mycall)
while syscall(__NR_mycall,a,b,c,d,e,f) becomes syscall6(mycall,a,b,c,d,e,f)
... and you thought you needed c++ for this
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Mon 04 Mar 2013, 01:27 Post subject:
|
|
here is a good link to some try-catch macros
http://www.di.unipi.it/~nids/docs/longjump_try_trow_catch.html
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
|
|
Page 2 of 2 [22 Posts] |
Goto page: Previous 1, 2 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|