Search code examples
cdecompilingida

what does (char *)__strdup do in c


int __cdecl sub_920(char *s1)
{
  void *v1; // esi
  char *ptr; // esi
  int v3; // edi

  v1 = off_2048;
  strlen((const char *)off_2048);
  ptr = (char *)__strdup(v1);
  memfrob(ptr);
  v3 = strcmp(s1, ptr);
  free(ptr);
  return v3;
}

This code was written by IDA, and I am not sure what ptr = (char *)__strdup(v1); actually does?


Solution

  • As can be read here: http://refspecs.linuxbase.org/LSB_3.0.0/LSB-PDA/LSB-PDA/baselib---strdup-1.html

    __strdup -- alias for strdup

    What strdup does can be read in this answer: https://stackoverflow.com/a/252802/6699433

    The short version is, it creates a copy of the string passed as argument and returns a pointer to the copy.