findme.c

来自「rsync的核心代码库。主要作用是比较二进制文件」· C语言 代码 · 共 44 行

C
44
字号
/* (C) 1998 Red Hat Software, Inc. -- Licensing details are in the COPYING   file accompanying popt source distributions, available from    ftp://ftp.redhat.com/pub/code/popt */#include "system.h"#include "findme.h"const char * findProgramPath(const char * argv0) {    char * path = getenv("PATH");    char * pathbuf;    char * start, * chptr;    char * buf;    /* If there is a / in the argv[0], it has to be an absolute       path */    if (strchr(argv0, '/'))	return xstrdup(argv0);    if (!path) return NULL;    start = pathbuf = alloca(strlen(path) + 1);    buf = malloc(strlen(path) + strlen(argv0) + 2);    strcpy(pathbuf, path);    chptr = NULL;    do {	if ((chptr = strchr(start, ':')))	    *chptr = '\0';	sprintf(buf, "%s/%s", start, argv0);	if (!access(buf, X_OK))	    return buf;	if (chptr) 	    start = chptr + 1;	else	    start = NULL;    } while (start && *start);    free(buf);    return NULL;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?