Skip to content

Instantly share code, notes, and snippets.

@masaedw
Created November 10, 2011 00:44
Show Gist options
  • Save masaedw/1353711 to your computer and use it in GitHub Desktop.
Save masaedw/1353711 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
// Lion だとこれは上書きされる
char* strdup(const char* arg)
{
printf("%s\n", "my strdup");
size_t len = strlen(arg) + 1;
return strncpy((char*)malloc(len), arg, len);
}
// これは無視されて標準のが使われる
// -fno-builtin を指定するとこの関数が有効になる
int printf(const char* fmt, ...)
{
va_list ap;
va_start(ap, fmt);
char* s = va_arg(ap, char*);
puts("my printf");
puts(s);
va_end(ap);
}
int main(int argc, char** argv)
{
char* hoge = "hogehoge";
char* fuga = strdup(hoge);
printf("%s\n", fuga);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment