Skip to content

Instantly share code, notes, and snippets.

@jordansissel
Created December 25, 2010 03:31
Show Gist options
  • Save jordansissel/754661 to your computer and use it in GitHub Desktop.
Save jordansissel/754661 to your computer and use it in GitHub Desktop.
strdup_r
syn(~) % ./a.out "hello"
Keyseq: hello
saveptr %p: 0x0
saveptr %s: (null)
syn(~) % ./a.out "hello world"
Keyseq: hello
saveptr %p: 0x800a04046
saveptr %s: world
% ./a.out "hello"
Keyseq: hello
saveptr %p: 0x2174015
saveptr %s:
% ./a.out "hello world"
Keyseq: hello
saveptr %p: 0x1ae0016
saveptr %s: world
#include <string.h>
#include <stdio.h>
int main(int argc, char **argv) {
char *line = strdup(argv[1]);
char *tokctx;
char *keyseq;
keyseq = strtok_r(line, " ", &tokctx);
printf("Keyseq: %s\n", keyseq);
printf("saveptr %%p: %p\n", tokctx);
printf("saveptr %%s: %s\n", tokctx);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment