char * _XlcFileName( XLCd lcd, const char *category) { char *siname; char cat[XLC_BUFSIZE], dir[XLC_BUFSIZE]; int i, n; char *args[NUM_LOCALEDIR]; char *file_name = NULL; if (lcd == (XLCd)NULL) return NULL; siname = XLC_PUBLIC(lcd, siname); if (category) lowercase(cat, category); else cat[0] = '\0'; xlocaledir(dir,XLC_BUFSIZE); n = _XlcParsePath(dir, args, NUM_LOCALEDIR); for (i = 0; i < n; ++i) { char buf[PATH_MAX], *name; if (args[i] == NULL) continue; name = NULL; if (snprintf(buf, PATH_MAX, "%s/%s.dir", args[i], cat) < PATH_MAX) { name = resolve_name(siname, buf, RtoL); } if (name == NULL) { continue; } if (*name == '/') { /* supposed to be absolute path name */ file_name = name; } else { if (snprintf(buf, PATH_MAX, "%s/%s", args[i], name) < PATH_MAX) file_name = strdup(buf); else file_name = NULL; Xfree(name); } if (file_name && isreadable(file_name)) { break; } Xfree(file_name); file_name = NULL; /* Then, try with next dir */ } return file_name; }
char * _XlcFileName( XLCd lcd, const char *category) { char *siname; char cat[XLC_BUFSIZE], dir[XLC_BUFSIZE]; int i, n; char *args[NUM_LOCALEDIR]; char *file_name = NULL; if (lcd == (XLCd)NULL) return NULL; siname = XLC_PUBLIC(lcd, siname); lowercase(cat, category); xlocaledir(dir,XLC_BUFSIZE); n = _XlcParsePath(dir, args, NUM_LOCALEDIR); for (i = 0; i < n; ++i) { char buf[PATH_MAX], *name; name = NULL; if ((5 + (args[i] ? strlen (args[i]) : 0) + (cat ? strlen (cat) : 0)) < PATH_MAX) { sprintf(buf, "%s/%s.dir", args[i], cat); name = resolve_name(siname, buf, RtoL); } if (name == NULL) { continue; } if (*name == '/') { /* supposed to be absolute path name */ file_name = name; } else { file_name = Xmalloc(2 + (args[i] ? strlen (args[i]) : 0) + (name ? strlen (name) : 0)); if (file_name != NULL) sprintf(file_name, "%s/%s", args[i], name); Xfree(name); } if (isreadable(file_name)) { break; } Xfree(file_name); file_name = NULL; /* Then, try with next dir */ } return file_name; }
int NC_infermodel(const char* path, int* omodep, int iscreate, int useparallel, void* params, NCmodel* model, char** newpathp) { int stat = NC_NOERR; char* newpath = NULL; NCURI* uri = NULL; int omode = *omodep; int isuri = 0; NClist* modeargs = nclistnew(); if((stat = processuri(path, &uri, &newpath, modeargs))) goto done; isuri = (uri != NULL); /* Phase 1: compute the IOSP */ if((stat = extractiosp(modeargs,omode,model))) goto done; assert(model->iosp != 0); /* Phase 2: Process the non-iosp mode arguments */ if(!modelcomplete(model) && isuri) { int i; for(i=0;i<nclistlength(modeargs);i++) { const char* arg = nclistget(modeargs,i); if((stat=processmodearg(arg,model))) goto done; } } /* Phase 3: See if we can infer DAP */ if(!modelcomplete(model) && isuri) { if((stat = NC_dapinfer(modeargs,model))) goto done; } /* Phase 4: mode inference */ if(!modelcomplete(model)) { if((stat = NC_omodeinfer(omode,model))) goto done; } /* Phase 5: Infer from file content, if possible; this has highest precedence, so it may override previous decisions. */ if(!iscreate && isreadable(model->iosp)) { /* Ok, we need to try to read the file */ if((stat = check_file_type(path, omode, useparallel, params, model, uri))) goto done; } /* Phase 6: Infer impl from format */ if(!modelcomplete(model)) { if((stat = NC_implinfer(useparallel, model))) goto done; } assert(modelcomplete(model)); /* Force flag consistency */ switch (model->impl) { case NC_FORMATX_NC4: case NC_FORMATX_NC_HDF4: case NC_FORMATX_DAP4: case NC_FORMATX_UDF0: case NC_FORMATX_UDF1: omode |= NC_NETCDF4; if(model->format == NC_FORMAT_NETCDF4_CLASSIC) omode |= NC_CLASSIC_MODEL; break; case NC_FORMATX_DAP2: omode &= ~(NC_NETCDF4|NC_64BIT_OFFSET|NC_64BIT_DATA); break; case NC_FORMATX_NC3: omode &= ~NC_NETCDF4; /* must be netcdf-3 (CDF-1, CDF-2, CDF-5) */ if(model->format == NC_FORMAT_64BIT_OFFSET) omode |= NC_64BIT_OFFSET; else if(model->format == NC_FORMAT_64BIT_DATA) omode |= NC_64BIT_DATA; break; case NC_FORMATX_PNETCDF: omode &= ~NC_NETCDF4; /* must be netcdf-3 (CDF-1, CDF-2, CDF-5) */ if(model->format == NC_FORMAT_64BIT_OFFSET) omode |= NC_64BIT_OFFSET; else if(model->format == NC_FORMAT_64BIT_DATA) omode |= NC_64BIT_DATA; break; default: {stat = NC_ENOTNC; goto done;} } done: if(uri) ncurifree(uri); nclistfreeall(modeargs); if(stat == NC_NOERR && newpathp) {*newpathp = newpath; newpath = NULL;} nullfree(newpath); *omodep = omode; /* in/out */ return check(stat); }
/* Functions */ int select (int fds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *timeout) { fd_set oread, owrite, oexcept; int ticks, start; int nfds; if (fds > _POSIX_FD_SETSIZE) { errno = EINVAL; return -1; } FD_ZERO (&oread); FD_ZERO (&owrite); FD_ZERO (&oexcept); nfds = 0; ticks = -1; if (timeout) { ticks = timeout->tv_sec * 100 + timeout->tv_usec / 10000; if (ticks < 0) { errno = EINVAL; return -1; } } start = _iocs_ontime (); for (;;) { { int fd; for (fd = 0; fd < fds; fd++) { int accmode; if (_fddb[fd].inuse == _FD_NOTUSED) continue; accmode = _fddb[fd].oflag & O_ACCMODE; if (isatty (fd)) { if (XFD_ISSET (fd, rfds) && isreadable (accmode) && _dos_k_keysns ()) { FD_SET (fd, &oread); nfds++; } if (XFD_ISSET (fd, wfds) && iswritable (accmode)) { FD_SET (fd, &owrite); nfds++; } } #if 0 else if (_fddb[fd].sockno >= 0) { if (XFD_ISSET (fd, rfds) && _socklen (_fddb[fd].sockno, 0)) { FD_SET (fd, &oread); nfds++; } if (XFD_ISSET (fd, wfds) /* && _socklen (_fddb[fd].sockno, 1) == 0 */) { FD_SET (fd, &owrite); nfds++; } } #endif else { if (XFD_ISSET (fd, rfds) && isreadable (accmode) && _dos_ioctrlis (fd)) { FD_SET (fd, &oread); nfds++; } if (XFD_ISSET (fd, wfds) && iswritable (accmode) && _dos_ioctrlos (fd)) { FD_SET (fd, &owrite); nfds++; } } } } { int rest; if ((rest = (_iocs_ontime () - start) % 8640000) < 0) rest += 8640000; if (nfds != 0) { if (ticks >= 0) { int left; if ((left = ticks - rest) < 0) left = 0; timeout->tv_sec = left / 100; timeout->tv_usec = (left % 100) * 10000; } if (rfds) *rfds = oread; if (wfds) *wfds = owrite; if (efds) *efds = oexcept; return nfds; } if (ticks >= 0 && rest > ticks) return 0; } _dos_change_pr (); } }
List *Find_Names (const char *repository, int which, int aflag, List **optentries, const char *virtual_repository) { List *entries; List *files; const char *regex = NULL; if(!current_parsed_root->isremote) regex = lookup_regex(virtual_repository); /* make a list for the files */ files = filelist = getlist (); /* look at entries (if necessary) */ if (which & W_LOCAL) { /* parse the entries file (if it exists) */ entries = Entries_Open (aflag, NULL); if (entries != NULL) { /* walk the entries file adding elements to the files list */ (void) walklist (entries, add_entries_proc, NULL); /* if our caller wanted the entries list, return it; else free it */ if (optentries != NULL) *optentries = entries; else Entries_Close (entries); } } if ((which & W_REPOS) && repository && !isreadable (CVSADM_ENTSTAT)) { /* search the repository */ if (find_rcs (repository, files, regex) != 0) { error (0, errno, "cannot open directory %s", fn_root(repository)); goto error_exit; } /* search the attic too */ { char *dir; dir = (char*)xmalloc (strlen (repository) + sizeof (CVSATTIC) + 10); (void) sprintf (dir, "%s/%s", repository, CVSATTIC); if (find_rcs (dir, files, regex) != 0 && !existence_error (errno)) /* For now keep this a fatal error, seems less useful for access control than the case above. */ error (1, errno, "cannot open directory %s", fn_root(dir)); xfree (dir); } if(find_virtual_rcs (virtual_repository, files) != 0) { error(1, errno, "find_virtual_rcs failed"); } if(find_rename_rcs(virtual_repository, files) != 0) { error(1,errno, "find_renames failed"); } } xfree(regex); /* sort the list into alphabetical order and return it */ sortlist (files, fsortcmp); return (files); error_exit: xfree(regex); dellist (&files); return NULL; }
cvsroot_t * Name_Root (const char *dir, const char *update_dir) { FILE *fpin; cvsroot_t *ret; const char *xupdate_dir; char *root = NULL; size_t root_allocated = 0; char *tmp; char *cvsadm; char *cp; int len; TRACE (TRACE_FLOW, "Name_Root (%s, %s)", dir ? dir : "(null)", update_dir ? update_dir : "(null)"); if (update_dir && *update_dir) xupdate_dir = update_dir; else xupdate_dir = "."; if (dir != NULL) { cvsadm = Xasprintf ("%s/%s", dir, CVSADM); tmp = Xasprintf ("%s/%s", dir, CVSADM_ROOT); } else { cvsadm = xstrdup (CVSADM); tmp = xstrdup (CVSADM_ROOT); } /* * Do not bother looking for a readable file if there is no cvsadm * directory present. * * It is possible that not all repositories will have a CVS/Root * file. This is ok, but the user will need to specify -d * /path/name or have the environment variable CVSROOT set in * order to continue. */ if ((!isdir (cvsadm)) || (!isreadable (tmp))) { ret = NULL; goto out; } /* * The assumption here is that the CVS Root is always contained in the * first line of the "Root" file. */ fpin = xfopen (tmp, "r"); if ((len = getline (&root, &root_allocated, fpin)) < 0) { int saved_errno = errno; /* FIXME: should be checking for end of file separately; errno is not set in that case. */ error (0, 0, "in directory %s:", xupdate_dir); error (0, saved_errno, "cannot read %s", CVSADM_ROOT); error (0, 0, "please correct this problem"); ret = NULL; goto out; } fclose (fpin); cp = root + len - 1; if (*cp == '\n') *cp = '\0'; /* strip the newline */ /* * root now contains a candidate for CVSroot. It must be an * absolute pathname or specify a remote server. */ ret = parse_cvsroot (root); if (ret == NULL) { error (0, 0, "in directory %s:", xupdate_dir); error (0, 0, "ignoring %s because it does not contain a valid root.", CVSADM_ROOT); goto out; } if (!ret->isremote && !isdir (ret->directory)) { error (0, 0, "in directory %s:", xupdate_dir); error (0, 0, "ignoring %s because it specifies a non-existent repository %s", CVSADM_ROOT, root); ret = NULL; goto out; } out: free (cvsadm); free (tmp); if (root != NULL) free (root); return ret; }