Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

basename() returning int?

Tags:

c

Probably something stupid I'm missing but, why am I getting this warning?

static void foo(char *path) {
    char *bname;
    char *path2 = strdup(path);
    bname = basename(path2);

(line with basename() call): warning: assignment makes pointer from integer without a cast

Indeed, if I change to this, the warning goes away:

    bname = (char *)basename(path2);

man 3 basename tells me:

char *basename(char *path);

Both dirname() and basename() return pointers to null-terminated strings.

What gives?

like image 966
EBM Avatar asked May 08 '10 07:05

EBM


1 Answers

Negative. It works properly to me. Are you sure you included the correct header?

#include <string.h>
#include <libgen.h>

static void foo(char *path) {
    char *bname;
    char *path2 = strdup(path);
    bname = basename(path2);
}

Could you tell us more about your compiling environment?

like image 71
Dacav Avatar answered Sep 28 '22 16:09

Dacav