Posted By

mwb1100 on 07/12/09


Tagged

domain public


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

mwb1100
tandouri


strdup()


 / Published in: C
 

  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include <assert.h>
  4.  
  5. /*
  6.  * public domain strdup()
  7.  */
  8.  
  9. char* strdup( char const* s)
  10. {
  11. size_t siz = 0;
  12. char* result = NULL;
  13.  
  14. assert( s);
  15.  
  16. siz = strlen( s) + 1;
  17. result = (char*) malloc( siz);
  18.  
  19. if (result) {
  20. memcpy( result, s, siz);
  21. }
  22.  
  23. return result;
  24. }

Report this snippet  

You need to login to post a comment.