Ejemplo n.º 1
0
int
zmain (void)
{
    size_t i = 0;
    int errors = 0;
    char path[1024];
    char *file;

    for (i = 0; i < sizeof (tests) / sizeof (tests [0]); ++i)
    {
        if (tests [i].path == NULL)
            file = __xpg_basename (NULL);
        else
        {
            strcpy (path, tests [i].path);
            file = __xpg_basename (path);
        }
        if (strcmp (file, tests [i].file))
        {
            printf ("Test with `%s' failed: Result is: `%s'.\n",
                    (tests [i].path == NULL ? "NULL" : tests [i].path), file);
            errors = 1;
        }
    }

    return errors;
}
Ejemplo n.º 2
0
string f$basename (const string &name, const string &suffix) {
  string name_copy (name.c_str(), name.size());
  dl::enter_critical_section();//OK
  const char *result_c_str = __xpg_basename (name_copy.buffer());
  dl::leave_critical_section();
  int l = (int)strlen (result_c_str);
  if ((int)suffix.size() <= l && !strcmp (result_c_str + l - suffix.size(), suffix.c_str())) {
    l -= suffix.size();
  }
  return string (result_c_str, (dl::size_type)l);
}