コード例 #1
0
ファイル: his.c プロジェクト: zhouqt/kbs
void HISmaint()
{
    FILE *hismaint;
    time_t lasthist, now;
    char maintbuff[4096];
    char *ptr;

    if (!isfile(HISTORY)) {
        makedbz(HISTORY, DEFAULT_HIST_SIZE);
    }
    hismaint = fopen(HISTORY, "r");
    if (hismaint == NULL) {
        return;
    }
    fgets(maintbuff, sizeof(maintbuff), hismaint);
    ptr = (char *) strchr(maintbuff, '\t');
    if (ptr != NULL) {
        ptr++;
        lasthist = atol(ptr);
        time(&now);
        if (lasthist + 86400 * Expiredays * 2 < now) {
            char newhistpath[1024];
            char newhistdirpath[1024];
            char newhistpagpath[1024];

            (void) HISclose();
            sprintf(newhistpath, "%s.n", HISTORY);
            sprintf(newhistdirpath, "%s.n.dir", HISTORY);
            sprintf(newhistpagpath, "%s.n.pag", HISTORY);
            if (!isfile(newhistdirpath)) {
                makedbz(newhistpath, DEFAULT_HIST_SIZE);
            }
            myHISsetup(newhistpath);
            while (fgets(maintbuff, sizeof(maintbuff), hismaint) != NULL) {
                datum key;

                ptr = (char *) strchr(maintbuff, '\t');
                if (ptr != NULL) {
                    *ptr = '\0';
                    ptr++;
                    lasthist = atol(ptr);
                } else {
                    continue;
                }
                if (lasthist + 99600 * Expiredays < now)
                    continue;
                key.dptr = maintbuff;
                key.dsize = strlen(maintbuff);
                myHISwrite(&key, ptr);
            }
            (void) HISclose();
            rename(HISTORY, (char *) fileglue("%s.o", HISTORY));
            rename(newhistpath, HISTORY);
            rename(newhistdirpath, (char *) fileglue("%s.dir", HISTORY));
            rename(newhistpagpath, (char *) fileglue("%s.pag", HISTORY));
            (void) HISsetup();
        }
    }
    fclose(hismaint);
}
コード例 #2
0
ファイル: mv.cpp プロジェクト: apfeltee/unixbox
DEFINE_MAIN_PROTO(mv, argc, argv) 
{
    int status;
    char *input;
    char *output;
    if(argc < 2) 
    {
        fprintf(stderr, "mv: missing file operand\n");
        return(1);
    }
    if(argc < 3)
    {
        fprintf(stderr, "mv: missing file operand after '%s'\n", argv[1]);
        return(1);
    }
    input = argv[1];
    output = argv[2];
    if(isfile(input) && isfile(output))
    {
        status = rename(input, output);
        if(status == -1)
        {
            bail(true, "mv: rename() from '%s' to '%s' failed", input, output);
            return 1;
        }
    }
    else
    {
        fprintf(stderr, "mv: not implemented yet\n");
    }
    return(0);
}
コード例 #3
0
ファイル: cache.c プロジェクト: GroupO/geeqie_zas
gchar *cache_find_location(CacheType type, const gchar *source)
{
	gchar *path;
	const gchar *cache_rc;
	const gchar *cache_local;
	const gchar *cache_ext;
	gboolean prefer_local;

	if (!source) return NULL;

	cache_path_parts(type, &cache_rc, &cache_local, &cache_ext);

	if (type == CACHE_TYPE_METADATA || type == CACHE_TYPE_XMP_METADATA)
		{
		prefer_local = options->metadata.enable_metadata_dirs;
		}
	else
		{
		prefer_local = options->thumbnails.cache_into_dirs;
		}

	if (prefer_local)
		{
		path = cache_build_path_local(source, cache_local, cache_ext);
		}
	else
		{
		path = cache_build_path_rc(source, cache_rc, cache_ext);
		}

	if (!isfile(path))
		{
		g_free(path);

		/* try the opposite method if not found */
		if (!prefer_local)
			{
			path = cache_build_path_local(source, cache_local, cache_ext);
			}
		else
			{
			path = cache_build_path_rc(source, cache_rc, cache_ext);
			}

		if (!isfile(path))
			{
			g_free(path);
			path = NULL;
			}
		}

	return path;
}
コード例 #4
0
static int
ismodule(char *filename) { /* Is module -- check for .pyc/.pyo too */
    if (isfile(filename))
        return 1;

    /* Check for the compiled version of prefix. */
    if (strlen(filename) < MAXPATHLEN) {
        strcat(filename, Py_OptimizeFlag ? "o" : "c");
        if (isfile(filename))
            return 1;
    }
    return 0;
}
コード例 #5
0
ファイル: rename.cpp プロジェクト: acml/cvsnt
static int validate_file(const char *filename, char **root, char **repository, const char **file, const char **returned_dir, int must_exist)
{
	char *dir = (char*)xmalloc(strlen(filename)+sizeof(CVSADM_REP)+sizeof(CVSADM_ROOT)+1),*p;
	size_t repos_len;
	FILE *fp;

	strcpy(dir,filename);
	p=(char*)last_component(dir);
	*file=last_component((char*)filename);
	*p='\0';

	strcat(dir,CVSADM);
	if(!isdir(dir))
		error(1,0,"%s is not part of a checked out repository",filename);
	*p='\0';
	strcat(dir,CVSADM_REP);
	if(!isfile(dir) || isdir(dir))
		error(1,0,"%s is not part of a checked out repository",filename);
	fp = fopen(dir,"r");
	if(!fp)
		error(1,errno,"Couldn't open %s", dir);
	*repository=NULL;
	if((repos_len=getline(repository,&repos_len,fp))<0)
		error(1,errno,"Couldn't read %s", dir);
	fclose(fp);
	(*repository)[repos_len-1]='\0';

	*p='\0';
	strcat(dir,CVSADM_ROOT);
	if(!isfile(dir) || isdir(dir))
		error(1,0,"%s is not part of a checked out repository",filename);
	fp = fopen(dir,"r");
	if(!fp)
		error(1,errno,"Couldn't open %s", dir);
	*root=NULL;
	if((repos_len=getline(root,&repos_len,fp))<0)
		error(1,errno,"Couldn't read %s", dir);
	fclose(fp);
	(*root)[repos_len-1]='\0';

	*p='\0';
	if(!strlen(dir))
		strcpy(dir,"./");

	*returned_dir = dir;

	TRACE(3,"%s is in %s/%s",PATCH_NULL(filename),PATCH_NULL(*root),PATCH_NULL(*repository));

	return 0;
}
コード例 #6
0
ファイル: getpath.c プロジェクト: 469306621/Languages
static int
ismodule(wchar_t *filename)        /* Is module -- check for .pyc/.pyo too */
{
    if (isfile(filename))
        return 1;

    /* Check for the compiled version of prefix. */
    if (wcslen(filename) < MAXPATHLEN) {
        wcscat(filename, Py_OptimizeFlag ? L"o" : L"c");
        if (isfile(filename))
            return 1;
    }
    return 0;
}
コード例 #7
0
ファイル: thumb_standard.c プロジェクト: thaidao/Workspace_Ex
static gint thumb_loader_std_next_source(ThumbLoaderStd *tl, gint remove_broken)
{
	image_loader_free(tl->il);
	tl->il = NULL;

	if (tl->thumb_path)
		{
		if (!tl->thumb_path_local && remove_broken)
			{
			if (debug) printf("thumb broken, unlinking: %s\n", tl->thumb_path);
			unlink_file(tl->thumb_path);
			}

		g_free(tl->thumb_path);
		tl->thumb_path = NULL;

		if (!tl->thumb_path_local)
			{
			tl->thumb_path = thumb_loader_std_cache_path(tl, TRUE, NULL, FALSE);
			if (isfile(tl->thumb_path) && thumb_loader_std_setup(tl, tl->thumb_path))
				{
				tl->thumb_path_local = TRUE;
				return TRUE;
				}

			g_free(tl->thumb_path);
			tl->thumb_path = NULL;
			}

		if (thumb_loader_std_setup(tl, tl->source_path)) return TRUE;
		}

	thumb_loader_std_save(tl, NULL);
	return FALSE;
}
コード例 #8
0
ファイル: web.c プロジェクト: otterley/grufti
void Web_catfile(dccrec *d, char *filename)
{
	FILE	*f;
	char	s[BUFSIZ];

	f = fopen(filename,"r");
	if(f == NULL)
	{
		Log_write(LOG_MAIN|LOG_ERROR,"*","No such file \"%s\".",filename);
		DCC_write(d,"Sorry, the owner has not created \"%s\".",filename);
		return;
	}

	if(!isfile(filename))
	{
		fclose(f);
		Log_write(LOG_ERROR,"*","\"%s\" is not a normal file.",filename);
		DCC_write(d,"\"%s\" is not a normal file.",filename);
		return;
	}

	while(readline(f,s))
	{
		Web_fixforhtml(s);
		DCC_write(d,"%s",s);
	}

	fclose(f);
}
コード例 #9
0
static void    readwordsfile(WORD_HASH_TABLE *table_ptr, char *stopw_file)
{
    char    line[MAXSTRLEN];
    FILE   *fp;
    StringList *sl;
    int     i;


    /* Not this reports "Sucess" on trying to open a directory. to lazy to fix now */

    if ((fp = fopen(stopw_file, F_READ_TEXT)) == NULL || !isfile(stopw_file))
        progerrno("Couldn't open the word file '%s': ", stopw_file);


    /* read all lines and store each word as stopword */

    while (fgets(line, MAXSTRLEN, fp) != NULL)
    {
        if (line[0] == '#' || line[0] == '\n')
            continue;

        sl = parse_line(line);
        if (sl && sl->n)
        {
            for (i = 0; i < sl->n; i++)
                add_word_to_hash_table( table_ptr, strtolower(sl->word[i]), HASHSIZE);

            freeStringList(sl);
        }
    }

    fclose(fp);
    return;
}
コード例 #10
0
ファイル: getpath.c プロジェクト: DinoV/cpython
static int
ismodule(wchar_t *filename)        /* Is module -- check for .pyc too */
{
    if (isfile(filename)) {
        return 1;
    }

    /* Check for the compiled version of prefix. */
    if (wcslen(filename) < MAXPATHLEN) {
        wcscat(filename, L"c");
        if (isfile(filename)) {
            return 1;
        }
    }
    return 0;
}
コード例 #11
0
ファイル: cache-loader.c プロジェクト: XelaRellum/geeqie
CacheLoader *cache_loader_new(FileData *fd, CacheDataType load_mask,
			      CacheLoaderDoneFunc done_func, gpointer done_data)
{
	CacheLoader *cl;
	gchar *found;

	if (!fd || !isfile(fd->path)) return NULL;

	cl = g_new0(CacheLoader, 1);
	cl->fd = file_data_ref(fd);

	cl->done_func = done_func;
	cl->done_data = done_data;

	found = cache_find_location(CACHE_TYPE_SIM, cl->fd->path);
	if (found && filetime(found) == filetime(cl->fd->path))
		{
		cl->cd = cache_sim_data_load(found);
		}
	g_free(found);

	if (!cl->cd) cl->cd = cache_sim_data_new();

	cl->todo_mask = load_mask;
	cl->done_mask = CACHE_LOADER_NONE;

	cl->il = NULL;
	cl->idle_id = g_idle_add(cache_loader_idle_cb, cl);

	cl->error = FALSE;

	return cl;
}
コード例 #12
0
ファイル: mkmodules.cpp プロジェクト: acml/cvsnt
static int checkout_file (const char *file, const char *directory, const char *temp, mode_t *mode)
{
    char *rcs;
    RCSNode *rcsnode;
    int retcode = 0;

    if (noexec)
		return 0;

    rcs = (char*)xmalloc (strlen (file) + strlen(directory) + 5);
	sprintf(rcs,"%s/%s%s",directory,file,RCSEXT);
    if (!isfile (rcs))
    {
		xfree (rcs);
		return (1);
    }
    rcsnode = RCS_parsercsfile (rcs);
	if(rcsnode)
		retcode = RCS_checkout (rcsnode, NULL, NULL, NULL, "b", (char*)temp, 
			    (RCSCHECKOUTPROC) NULL, (void *) NULL, mode);
    if (rcsnode && retcode != 0)
    {
		/* Probably not necessary (?); RCS_checkout already printed a
		message.  */
		error (0, 0, "failed to check out %s file",
			file);
    }
    freercsnode (&rcsnode);
    xfree (rcs);
    return (retcode);
}
コード例 #13
0
ファイル: mod_ident.c プロジェクト: PichuChen/formosa
static int a_encode(const char *file1, const char *file2, const char *file3)
{
#ifdef IDENT_PGP_ENCODE
	char gbuf[128];
#endif

	if (mycp(file1, file2) == -1)
		return -1;
#ifdef IDENT_PGP_ENCODE
#ifdef NSYSUBBS
	sprintf(gbuf, "%s -e %s \"%s\"", BIN_PGP, file2, PUBLIC_KEY);
	system(gbuf);
	sprintf(gbuf, "%s.pgp", file2);
	if (isfile(gbuf))
	{
		if (rename(gbuf, file3) == 0)
		{
			unlink(file2);
			return 0;
		}
	}
#endif
#endif

	if (rename(file2, file3) == -1)
	{
		unlink(file2);
		return -1;
	}
	return 0;
}
コード例 #14
0
ファイル: hypermail.c プロジェクト: LeoNelson/hypermail
static char *expand_contents(char *variable)
{
    char *return_value = NULL;

    /*
     * Potentially read the header and footer files. Check to make
     * sure the value is a valid file or else assure the original
     * value is there.
     */
    if (variable) {
	/*
	 * Check if valid filename. If not then just return the
	 * variable listed. 
	 * NOTE !! This really should be an error message!
	 */
	if (isfile(variable)) {
	    /* 
	     * Now try to assign the contents of the file to
	     * the return value. If it is able to read the file
	     * then free the existing storage and return.
	     * If not then just return the existing value.
	     * NOTE !! This really should be an error message!
	     */
	    return_value = getfilecontents(variable);
	}
    }
    return return_value;
}
コード例 #15
0
ファイル: cache_maint.c プロジェクト: GroupO/geeqie_zas
static void cache_file_remove(const gchar *path)
{
	if (path && isfile(path) && !unlink_file(path))
		{
		DEBUG_1("Failed to remove cache file %s", path);
		}
}
コード例 #16
0
ファイル: FileMetaDAO.cpp プロジェクト: Thirdhuku/CloudStore
ReturnStatus
FileMetaDAO::updateFile(const std::string &path, const FileMeta &meta,
                        FileMeta *pMeta, int *pDelta)
{
	Channel* pDataChannel = ChannelManager::getInstance()->Mapping(m_BucketId);
	NameSpace *DataNS = pDataChannel->m_DataNS;
	
    int rt = 0;
    Args fd;

    ReturnStatus rs;

    rs = isfile(path);

    if (!rs.success()) {
        return rs;
    }

    fd = DataNS->Open(path.c_str(), O_RDWR);

    if (-1 == rt) {
        ERROR_LOG("path %s, open() error, %s.", path.c_str(), strerror(errno));

        // already check path errors in isfile()
        return ReturnStatus(MU_FAILED, MU_UNKNOWN_ERROR);
    }


    // check file version

    FileAttr attr;

    rt = DataNS->readn(&fd, &attr, sizeof(attr));

    if (sizeof(attr) != rt) {
        ERROR_LOG("readn() error");
        DataNS->Close(&fd);
        return ReturnStatus(MU_FAILED, MU_UNKNOWN_ERROR);
    }

    if (meta.m_Attr.m_Version != attr.m_Version + 1) {
        ERROR_LOG("version outdated, current version %" PRIu64 ", "
                  "received version %" PRIu64,
                  attr.m_Version, meta.m_Attr.m_Version);
        DataNS->Close(&fd);
        pMeta->m_Attr = attr;
        return ReturnStatus(MU_FAILED, VERSION_OUTDATED);
    }

    // write metadata

    rs = writeFileMeta(&fd, meta);

    DataNS->Close(&fd);;

    // return file size delta
    *pDelta = meta.m_Attr.m_Size - attr.m_Size;

    return rs;
}
コード例 #17
0
ファイル: login.c プロジェクト: morrisxd/PMC
/* The return value will need to be freed. */
static char *
construct_cvspass_filename ()
{
    char *homedir;
    char *passfile;

    /* Environment should override file. */
    if ((passfile = getenv ("CVS_PASSFILE")) != NULL)
	return xstrdup (passfile);

    /* Construct absolute pathname to user's password file. */
    /* todo: does this work under OS/2 ? */
    homedir = get_homedir ();
    if (! homedir)
    {
	/* FIXME?  This message confuses a lot of users, at least
	   on Win95 (which doesn't set HOMEDRIVE and HOMEPATH like
	   NT does).  I suppose the answer for Win95 is to store the
	   passwords in the registry or something (??).  And .cvsrc
	   and such too?  Wonder what WinCVS does (about .cvsrc, the
	   right thing for a GUI is to just store the password in
	   memory only)...  */
	error (1, 0, "could not find out home directory");
	return (char *) NULL;
    }

    passfile = strcat_filename_onto_homedir (homedir, CVS_PASSWORD_FILE);

    /* Safety first and last, Scouts. */
    if (isfile (passfile))
	/* xchmod() is too polite. */
	chmod (passfile, 0600);

    return passfile;
}
コード例 #18
0
ファイル: formosa.c プロジェクト: PichuChen/formosa
/***********************************************************
*		ANNOUNCE
*			取得近站公告
************************************************************/
DoAnnounce()
{
	if (!isfile(WELCOME))
		RespondProtocol(NO_ANNOUNCE);
	else
		SendArticle(WELCOME, TRUE);
}
コード例 #19
0
ファイル: ui_fileops.c プロジェクト: tjwei/WebKitGtkKindleDXG
gint file_in_path(const gchar *name)
{
	gchar *path;
	gchar *namel;
	gint p, l;
	gint ret = FALSE;

	if (!name) return FALSE;
	path = g_strdup(getenv("PATH"));
	if (!path) return FALSE;
	namel = path_from_utf8(name);

	p = 0;
	l = strlen(path);
	while (p < l && !ret)
		{
		gchar *f;
		gint e = p;
		while (path[e] != ':' && path[e] != '\0') e++;
		path[e] = '\0';
		e++;
		f = g_strconcat(path + p, "/", namel, NULL);
		if (isfile(f)) ret = TRUE;
		g_free(f);
		p = e;
		}
	g_free(namel);
	g_free(path);

	return ret;
}
コード例 #20
0
ファイル: pl.c プロジェクト: DJHartley/pkg_install
/* Add an MD5 checksum entry for a file or link */
void
add_cksum(Package *pkg, PackingList p, const char *fname)
{
    char *cp = NULL, buf[33];

    if (issymlink(fname)) {
	int len;
	char lnk[FILENAME_MAX];

	if ((len = readlink(fname, lnk, FILENAME_MAX)) > 0)
	    cp = MD5Data((unsigned char *)lnk, len, buf);
    } else if (isfile(fname)) {
	/* Don't record MD5 checksum for device nodes and such */
	cp = MD5File(fname, buf);
    }

    if (cp != NULL) {
	PackingList tmp = new_plist_entry();

	tmp->name = copy_string(strconcat("MD5:", cp));
	tmp->type = PLIST_COMMENT;
	tmp->next = p->next;
	tmp->prev = p;
	p->next = tmp;
	if (pkg->tail == p)
	    pkg->tail = tmp;
    }
}
コード例 #21
0
ファイル: fscmd.c プロジェクト: CoryXie/nix-os
/*
 * Walks elems starting at f.
 * Ok if nelems is 0.
 */
static Path*
walkpath(Memblk *f, char *elems[], int nelems)
{
	int i;
	Memblk *nf;
	Path *p;

	p = newpath(f);
	if(catcherror()){
		putpath(p);
		error(nil);
	}
	isfile(f);
	for(i = 0; i < nelems; i++){
		if((f->d.mode&DMDIR) == 0)
			error("not a directory");
		rwlock(f, Rd);
		if(catcherror()){
			rwunlock(f, Rd);
			error("walk: %r");
		}
		nf = dfwalk(f, elems[i], Rd);
		rwunlock(f, Rd);
		addelem(&p, nf);
		mbput(nf);
		f = nf;
		USED(&f);	/* in case of error() */
		noerror();
	}
	noerror();
	return p;
}
コード例 #22
0
ファイル: FileMetaDAO.cpp プロジェクト: Thirdhuku/CloudStore
ReturnStatus
FileMetaDAO::movFile(const std::string &srcPath,
                     const std::string &destPath)
{
	Channel* pDataChannel = ChannelManager::getInstance()->Mapping(m_BucketId);
	NameSpace *DataNS = pDataChannel->m_DataNS;
	
    int rt = 0;
    int error = 0;

    ReturnStatus rs;

    // check src path

    rs = isfile(srcPath);

    if (!rs.success()) {
        if (IS_DIRECTORY == rs.errorCode) {
            return ReturnStatus(MU_FAILED, SRC_PATH_IS_DIRECTORY);

        } else if (PATH_INVALID == rs.errorCode) {
            return ReturnStatus(MU_FAILED, SRC_PATH_INVALID);

        } else if (PATH_NOT_EXIST == rs.errorCode) {
            return ReturnStatus(MU_FAILED, SRC_PATH_NOT_EXIST);
        }

        return rs;
    }

    // check dest path

    rs = isdir(prefix(destPath));

    if (!rs.success()) {
        if (MU_UNKNOWN_ERROR != rs.errorCode) {
            return ReturnStatus(MU_FAILED, DEST_PATH_INVALID);
        }

        return rs;
    }

    rt = DataNS->Move(srcPath.c_str(), destPath.c_str());

    if (-1 == rt) {
        error = errno;
        ERROR_LOG("src path %s, dest path %s, rename() error, %s.",
                  srcPath.c_str(), destPath.c_str(), strerror(error));

        if (EISDIR == error) {
            return ReturnStatus(MU_FAILED, DEST_PATH_IS_DIRECTORY);

        } else {
            return ReturnStatus(MU_FAILED, MU_UNKNOWN_ERROR);
        }
    }

    return ReturnStatus(MU_SUCCESS);
}
コード例 #23
0
ファイル: cache.c プロジェクト: gentoo/pornview
static void
cache_file_remove (const gchar * path)
{
    if (path && isfile (path) && unlink (path) < 0)
    {
	printf ("Failed to remove cache file %s\n", path);
    }
}
コード例 #24
0
ファイル: getpath.c プロジェクト: AbnerChang/edk2-staging
/** Determine if filename refers to a Python module.

    A Python module is indicated if the file exists, or if the file with
    'o' or 'c' appended exists.

    @param[in]    filename    The fully qualified path to the object to test.

    @retval       0
**/
static int
ismodule(char *filename)
{
  if (isfile(filename)) {
    //if (Py_VerboseFlag) PySys_WriteStderr("%s[%d]: file = \"%s\"\n", __func__, __LINE__, filename);
    return 1;
  }

    /* Check for the compiled version of prefix. */
    if (strlen(filename) < MAXPATHLEN) {
        strcat(filename, Py_OptimizeFlag ? "o" : "c");
        if (isfile(filename)) {
          return 1;
        }
    }
    return 0;
}
コード例 #25
0
ファイル: getpath.c プロジェクト: 469306621/Languages
/* search_for_prefix requires that argv0_path be no more than MAXPATHLEN
   bytes long.
*/
static int
search_for_prefix(wchar_t *argv0_path, wchar_t *home, wchar_t *_prefix)
{
    size_t n;
    wchar_t *vpath;

    /* If PYTHONHOME is set, we believe it unconditionally */
    if (home) {
        wchar_t *delim;
        wcsncpy(prefix, home, MAXPATHLEN);
        delim = wcschr(prefix, DELIM);
        if (delim)
            *delim = L'\0';
        joinpath(prefix, lib_python);
        joinpath(prefix, LANDMARK);
        return 1;
    }

    /* Check to see if argv[0] is in the build directory */
    wcscpy(prefix, argv0_path);
    joinpath(prefix, L"Modules/Setup");
    if (isfile(prefix)) {
        /* Check VPATH to see if argv0_path is in the build directory. */
        vpath = _Py_char2wchar(VPATH, NULL);
        if (vpath != NULL) {
            wcscpy(prefix, argv0_path);
            joinpath(prefix, vpath);
            PyMem_Free(vpath);
            joinpath(prefix, L"Lib");
            joinpath(prefix, LANDMARK);
            if (ismodule(prefix))
                return -1;
        }
    }

    /* Search from argv0_path, until root is found */
    copy_absolute(prefix, argv0_path, MAXPATHLEN+1);
    do {
        n = wcslen(prefix);
        joinpath(prefix, lib_python);
        joinpath(prefix, LANDMARK);
        if (ismodule(prefix))
            return 1;
        prefix[n] = L'\0';
        reduce(prefix);
    } while (prefix[0]);

    /* Look at configure's PREFIX */
    wcsncpy(prefix, _prefix, MAXPATHLEN);
    joinpath(prefix, lib_python);
    joinpath(prefix, LANDMARK);
    if (ismodule(prefix))
        return 1;

    /* Fail */
    return 0;
}
コード例 #26
0
ファイル: bbsnnrp.c プロジェクト: yrchen/Athena
void
doterm(int s)
{
  printf("bbsnnrp terminated.  Signal %d\n", s);
  writerc(&BBSNNRP);
  if (isfile(LockFile))
    unlink(LockFile);
  exit(1);
}
コード例 #27
0
ファイル: show.c プロジェクト: DJHartley/pkg_install
/* Show files that don't match the recorded checksum */
int
show_cksum(const char *title, Package *plist)
{
    PackingList p;
    const char *dir = ".";
    char *prefix = NULL;
    char tmp[FILENAME_MAX];
    int errcode = 0;

    if (!Quiet) {
	printf("%s%s", InfoPrefix, title);
	fflush(stdout);
    }

    for (p = plist->head; p != NULL; p = p->next)
	if (p->type == PLIST_CWD) {
	    if (!prefix)
		prefix = p->name;
	    if (p->name == NULL)
		dir = prefix;
	    else
		dir = p->name;
	} else if (p->type == PLIST_FILE) {
	    snprintf(tmp, FILENAME_MAX, "%s/%s", elide_root(dir), p->name);
	    if (!fexists(tmp)) {
		warnx("%s doesn't exist", tmp);
		errcode = 1;
	    } else if (p->next && p->next->type == PLIST_COMMENT &&
	             (strncmp(p->next->name, "MD5:", 4) == 0)) {
		char *cp = NULL, buf[33];

		/*
		 * For packing lists whose version is 1.1 or greater, the md5
		 * hash for a symlink is calculated on the string returned
		 * by readlink().
		 */
		if (issymlink(tmp) && verscmp(plist, 1, 0) > 0) {
		    int len;
		    char linkbuf[FILENAME_MAX];

		    if ((len = readlink(tmp, linkbuf, FILENAME_MAX)) > 0)
			cp = MD5Data((unsigned char *)linkbuf, len, buf);
		} else if (isfile(tmp) || verscmp(plist, 1, 1) < 0)
		    cp = MD5File(tmp, buf);

		if (cp != NULL) {
		    /* Mismatch? */
		    if (strcmp(cp, p->next->name + 4))
			printf("%s fails the original MD5 checksum\n", tmp);
		    else if (Verbose)
			printf("%s matched the original MD5 checksum\n", tmp);
		}
	    }
	}
    return (errcode);
}
コード例 #28
0
ファイル: file.c プロジェクト: edgar-pek/PerspicuOS
char *
fileFindByPath(const char *base, const char *fname)
{
    static char tmp[FILENAME_MAX];
    char *cp;
    const char *suffixes[] = {".tbz", ".tgz", ".tar", NULL};
    int i;

    if (fexists(fname) && isfile(fname)) {
	strcpy(tmp, fname);
	return tmp;
    }
    if (base) {
	strcpy(tmp, base);

	cp = strrchr(tmp, '/');
	if (cp) {
	    *cp = '\0';	/* chop name */
	    cp = strrchr(tmp, '/');
	}
	if (cp)
	    for (i = 0; suffixes[i] != NULL; i++) {
		*(cp + 1) = '\0';
		strcat(cp, "All/");
		strcat(cp, fname);
		strcat(cp, suffixes[i]);
		if (fexists(tmp))
		    return tmp;
	    }
    }

    cp = getenv("PKG_PATH");
    while (cp) {
	char *cp2 = strsep(&cp, ":");

	for (i = 0; suffixes[i] != NULL; i++) {
	    snprintf(tmp, FILENAME_MAX, "%s/%s%s", cp2 ? cp2 : cp, fname, suffixes[i]);
	    if (fexists(tmp) && isfile(tmp))
		return tmp;
	}
    }
    return NULL;
}
コード例 #29
0
ファイル: ace_str.c プロジェクト: idx0/ace
board_file_t file_from_char(const char c)
{
	board_file_t f = FA;

	if (isfile(c)) {
		f = (board_file_t)(c - 'a');
	}

	return f;
}
コード例 #30
0
ファイル: his.c プロジェクト: zhouqt/kbs
void mkhistory(char *srchist)
{
    FILE *hismaint;
    char maintbuff[256];
    char *ptr;

    hismaint = fopen(srchist, "r");
    if (hismaint == NULL) {
        return;
    }
    {
        char newhistpath[1024];
        char newhistdirpath[1024];
        char newhistpagpath[1024];

        sprintf(newhistpath, "%s.n", srchist);
        sprintf(newhistdirpath, "%s.n.dir", srchist);
        sprintf(newhistpagpath, "%s.n.pag", srchist);
        if (!isfile(newhistdirpath) || !isfile(newhistpagpath)) {
            makedbz(newhistpath, DEFAULT_HIST_SIZE);
        }
        myHISsetup(newhistpath);
        while (fgets(maintbuff, sizeof(maintbuff), hismaint) != NULL) {
            datum key;

            ptr = (char *) strchr(maintbuff, '\t');
            if (ptr != NULL) {
                *ptr = '\0';
                ptr++;
            }
            key.dptr = maintbuff;
            key.dsize = strlen(maintbuff);
            myHISwrite(&key, ptr);
        }
        (void) HISclose();
        /*
         * rename(newhistpath, srchist);
         * rename(newhistdirpath, fileglue("%s.dir", srchist));
         * rename(newhistpagpath, fileglue("%s.pag", srchist));
         */
    }
    fclose(hismaint);
}