|
|
Log in / Subscribe / Register

find_debugfs()

    #define MAX_PATH 256
    #define _STR(x) #x
    #define STR(x) _STR(x)
    static const char *find_debugfs(void)
    {
	    static char debugfs[MAX_PATH+1];
	    static int debugfs_found;
	    char type[100];
	    FILE *fp;

	    if (debugfs_found)
		    return debugfs;

	    if ((fp = fopen("/proc/mounts","r")) == NULL)
		    return NULL;

	    while (fscanf(fp, "%*s %"
			  STR(MAX_PATH)
			  "s %99s %*s %*d %*d\n",
			  debugfs, type) == 2) {
		    if (strcmp(type, "debugfs") == 0)
			    break;
	    }
	    fclose(fp);

	    if (strcmp(type, "debugfs") != 0)
		    return NULL;

	    debugfs_found = 1;

	    return debugfs;
    }



to post comments

find_debugfs()

Posted Dec 30, 2009 19:54 UTC (Wed) by nevyn (guest, #33129) [Link]

Why hard code 256 instead of (at a minimum) use PATH_MAX?

% getconf PATH_MAX /
4096


Copyright © 2009, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds