Exemplo n.º 1
0
main()
{
	char pathname[MAXPATHLEN + 1];

	if (getwd(pathname) == NULL) {
		fprintf(stderr, "pwd: %s\n", pathname);
		exit(1);
	}
	printf("%s\n", pathname);
	exit(0);
}
Exemplo n.º 2
0
Arquivo: system.c Projeto: BrEacK/mc
/*******************************************************************
system wrapper for getwd
********************************************************************/
char *
sys_getwd (char *s)
{
    char *wd;
#ifdef HAVE_GETCWD
    wd = (char *) getcwd (s, sizeof (pstring));
#else
    wd = (char *) getwd (s);
#endif
    return wd;
}
Exemplo n.º 3
0
static void CmdLib_getwd( char *out, int outSize )
{
#if defined( _WIN32 ) || defined( WIN32 )
	_getcwd( out, outSize );
	Q_strncat( out, "\\", outSize, COPY_ALL_CHARACTERS );
#else
	getwd(out);
	strcat(out, "/");
#endif
	Q_FixSlashes( out );
}
Exemplo n.º 4
0
static void
initdirname(void)
{
#if defined(SYSV) || defined(USG)  /* handle both Sys Vr2 and Vr3 curses */
	(void) getcwd(dirname, BUFSIZ-2);
#else
	(void) getwd(dirname);
#endif /* SYSV || USG */
	if (verbose)
		(void) fprintf(trace, "current directory name=%s.\n", dirname);
	environ = newenviron;
}
Exemplo n.º 5
0
int
main(int argc, char **argv)
{
    char wd[MAXPATHLEN];
    char *path;

    ASSERT(path = getcwd(wd, sizeof wd));
    printf("getcwd => %s\n", path);
    ASSERT(path = getwd(wd));
    printf("getwd => %s\n", path);
    SUCCEED;
}
Exemplo n.º 6
0
void getCwd(Firebird::PathName& pn)
{
	char* buffer = pn.getBuffer(MAXPATHLEN);
#if defined(WIN_NT)
	_getcwd(buffer, MAXPATHLEN);
#elif defined(HAVE_GETCWD)
	FB_UNUSED(getcwd(buffer, MAXPATHLEN));
#else
	FB_UNUSED(getwd(buffer));
#endif
	pn.recalculate_length();
}
Exemplo n.º 7
0
int main(int argc, char* argv[]) {

 int t=-1,ex=0 ;
 char Path[4096];
 if(argc < 2){
  t = -1;
   
   strcpy(Path,".");
   strcpy(path,".");
   ls(path,Path,t);
   return 0;
  }
   if(argc>=2){ 
    if(strcmp(argv[1],"-i")==0) t = 1;
    else if(strcmp(argv[1],"-l")==0) t = 2;
    else if(strcmp(argv[1] ,"-R")==0) t = 3;
    else if(strcmp(argv[1],"-il")==0 || strcmp(argv[1],"-li")==0 ) t = 5;
    else if(strcmp(argv[1],"-iR")==0|| strcmp(argv[1],"-Ri")==0) t = 6;
    else if(strcmp(argv[1],"-lR")==0 || strcmp(argv[1],"-Rl")==0) t = 9;
    else if(strcmp(argv[1],"-ilR")==0|| strcmp(argv[1],"-iRl")==0 || strcmp(argv[1],"-Ril")==0 || strcmp(argv[1],"-Rli")==0 || strcmp(argv[1],"-liR")==0 || strcmp(argv[1],"-lRi")==0) t = 12;
    }
  if(t == -1 && argc ==2){ 
      strcpy(path,argv[1]);
      chdir(path);
      strcpy(Path,argv[1]);
      ls(path,Path,t);  
      return 0;    
    }
  if(t!=-1 && argc == 2){
   strcpy(Path,".");
   strcpy(path,".");
   if ((t%3)==0) printf(" %s : \n",path);
   ls(path,Path,t);
   return 0;
  }  
 if(argc>=3){
    int i,start;
    if(t==-1) start=1;
    else start=2;
    for(i=start;i<argc;i++){
      strcpy(path,argv[i]);
      chdir(path);
      if ((t%3)==0) printf(" %s : \n",path);
      printf(" %s \n",path);
      strcpy(Path,argv[i]);
      ls(path,Path,t);  
      getwd(path);
      chdir(path);
    }
   return 0;
 }
}
Exemplo n.º 8
0
Face*
dirface(char *dir, char *num)
{
	Face *f;
	char *from, *date;
	char buf[1024], pwd[1024], *info, *p, *digest;
	int n, fd;
	ulong len;

	/*
	 * loadmbox leaves us in maildir, so we needn't
	 * walk /mail/fs/mbox for each face; this makes startup
	 * a fair bit quicker.
	 */
	if(getwd(pwd, sizeof pwd) != nil && strcmp(pwd, dir) == 0)
		sprint(buf, "%s/info", num);
	else
		sprint(buf, "%s/%s/info", dir, num);
	len = dirlen(buf);
	if(len <= 0)
		return nil;
	fd = open(buf, OREAD);
	if(fd < 0)
		return nil;
	info = emalloc(len+1);
	n = readn(fd, info, len);
	close(fd);
	if(n < 0){
		free(info);
		return nil;
	}
	info[n] = '\0';
	f = emalloc(sizeof(Face));
	from = iline(info, &p);	/* from */
	iline(p, &p);	/* to */
	iline(p, &p);	/* cc */
	iline(p, &p);	/* replyto */
	date = iline(p, &p);	/* date */
	setname(f, estrdup(from));
	f->time = parsedate(date);
	f->tm = *localtime(f->time);
	sprint(buf, "%s/%s", dir, num);
	f->str[Sshow] = estrdup(buf);
	iline(p, &p);	/* subject */
	iline(p, &p);	/* mime content type */
	iline(p, &p);	/* mime disposition */
	iline(p, &p);	/* filename */
	digest = iline(p, &p);	/* digest */
	f->str[Sdigest] = estrdup(digest);
	free(info);
	return f;
}
Exemplo n.º 9
0
Arquivo: pwd.c Projeto: 99years/plan9
void
main(int argc, char *argv[])
{
	char pathname[512];

	USED(argc, argv);
	if(getwd(pathname, sizeof(pathname)) == 0) {
		fprint(2, "pwd: %r\n");
		exits("getwd");
	}
	print("%s\n", pathname);
	exits(0);
}
Exemplo n.º 10
0
Arquivo: lex.c Projeto: hfeeki/go
void
cinit(void)
{
	Sym *s;
	int i;

	nullgen.sym = S;
	nullgen.offset = 0;
	if(FPCHIP)
		nullgen.dval = 0;
	for(i=0; i<sizeof(nullgen.sval); i++)
		nullgen.sval[i] = 0;
	nullgen.type = D_NONE;
	nullgen.index = D_NONE;
	nullgen.scale = 0;

	nerrors = 0;
	iostack = I;
	iofree = I;
	peekc = IGN;
	nhunk = 0;
	for(i=0; i<NHASH; i++)
		hash[i] = S;
	for(i=0; itab[i].name; i++) {
		s = slookup(itab[i].name);
		if(s->type != LNAME)
			yyerror("double initialization %s", itab[i].name);
		s->type = itab[i].type;
		s->value = itab[i].value;
	}

	pathname = allocn(pathname, 0, 100);
	if(getwd(pathname, 99) == 0) {
		pathname = allocn(pathname, 100, 900);
		if(getwd(pathname, 999) == 0)
			strcpy(pathname, "/???");
	}
}
Exemplo n.º 11
0
int btFiles::BuildFromFS(const char *pathname)
{
  struct stat sb;
  BTFILE *pbf = (BTFILE*) 0;

  if( stat(pathname, &sb) < 0 ){
    fprintf(stderr,"error, stat file %s failed, %s\n",pathname,strerror(errno));
    return -1;
  }

  if( S_IFREG & sb.st_mode ){
    pbf = _new_bfnode();
#ifndef WINDOWS
    if( !pbf ) return -1;
#endif
    pbf->bf_length = m_total_files_length = sb.st_size;
    pbf->bf_filename = new char[strlen(pathname) + 1];
#ifndef WINDOWS
    if( !pbf->bf_filename ) return -1;
#endif
    strcpy(pbf->bf_filename, pathname);
    m_btfhead = pbf;
  }else if( S_IFDIR & sb.st_mode ){
    char wd[MAXPATHLEN];
    
#if HAVE_GETCWD
    if( !getcwd(wd,MAXPATHLEN) ) return -1;
#else
    if( !getwd(wd) ) return -1;
#endif
    
    m_directory = new char[strlen(pathname) + 1];
#ifndef WINDOWS
    if( !m_directory ) return -1;
#endif
    strcpy(m_directory, pathname);
    
    if(chdir(m_directory) < 0){
      fprintf(stderr,"error, change work directory to %s failed, %s",m_directory, strerror(errno));
      return -1;
    }

    if(_btf_recurses_directory((const char*)0, (BTFILE*) 0) < 0) return -1;
    if( chdir(wd) < 0) return -1;
  }else{
    fprintf(stderr,"error, %s is not a directory or regular file.\n",pathname);
    return -1;
  }
  return 0;
}
Exemplo n.º 12
0
static int
lua_cwd(lua_State *L)
{
#ifdef _WIN32

  char drv[2];
  int l;
  SB sb;
  sbinit(&sb);
  drv[0] = '.'; drv[1] = 0;
  l = GetFullPathNameA(drv, sb.maxlen, sb.buffer, 0);
  if (l > sb.maxlen) {
    sbgrow(&sb, l+1);
    l = GetFullPathNameA(drv, sb.maxlen, sb.buffer, 0);
  }
  if (l <= 0)
    return sbsetpush(L, &sb, ".");
  sb.len += l;
  return sbpush(L, &sb);

#elif HAVE_GETCWD
  
  const char *s;
  SB sb;
  sbinit(&sb);
  s = getcwd(sb.buffer, sb.maxlen);
  while (!s && errno==ERANGE)
    {
      sbgrow(&sb, sb.maxlen + SBINCREMENT);
      s = getcwd(sb.buffer, sb.maxlen);
    }
  if (! s)
    return sbsetpush(L, &sb, ".");
  sb.len += strlen(s);
  return sbpush(L, &sb);

#else
  
  const char *s;
  SB sb;
  sbinit(&sb);
  sbgrow(&sb, PATH_MAX); 
  s = getwd(sb.buffer);
  if (! s)
    return sbsetpush(L, &sb, ".");
  sb.len += strlen(s);
  return sbpush(L, &sb);

#endif
}
Exemplo n.º 13
0
static unsigned long
find_file(int sock_fd, char *arg, uintptr_t linenum)
{
    char buf[PATH_MAX];
    char *filename;
    size_t filename_len;
    uint8_t req = !opt_quiet ? req_find_file : req_find_file_async;
    uintptr_t result = 0;

    /* Make sure the filename is absolute; the server could have
       a different working directory to us.  */
    if(*arg != '/' && *arg != '~')
    {
	char *end;
#ifdef HAVE_GETCWD
	if(!getcwd(buf, PATH_MAX))
#else
	if(!getwd(buf))
#endif
	{
	    perror("getcwd");
	    exit(5);
	}
	end = buf + strlen(buf);
	if(end[-1] != '/')
	    *end++ = '/';
	strcpy(end, arg);
	filename = buf;
    }
    else
	filename = arg;

    /* Protocol input is [req_find_file:uint8_t, FILE-NAME-LEN:size_t,
       FILE-NAME:*, LINE:uintptr_t], output is [RES:uintptr_t], all in
       the local byte-order. */

    filename_len = strlen(filename);

    if(write(sock_fd, &req, sizeof(req)) != sizeof(req)
       || write(sock_fd, &filename_len, sizeof(filename_len)) != sizeof(filename_len)
       || write(sock_fd, filename, filename_len) != filename_len
       || write(sock_fd, &linenum, sizeof(linenum)) != sizeof(linenum)
       || (req != req_find_file_async
	   && read(sock_fd, &result, sizeof(result)) != sizeof(result)))
    {
	perror("find_file");
	return 10;
    }
    return result;
}
Exemplo n.º 14
0
char *
external_pwd()
{
    char *getwd();
    char *p = getwd(Name);

    if (p)
	/* PSL convention, terminate directory strings with a slash. */
	strcat(Name, "/");
    else
	/* An error occurred, just return NULL string. */
	Name[0] = 0;
    return Name;
} 
Exemplo n.º 15
0
Arquivo: zfgcwd.c Projeto: pkgw/iraf
/* ZFGCWD -- Get working (current) UNIX directory.  The current working
 * directory, once set, is saved in oscwd.
 */
int
ZFGCWD (
  PKCHAR  *outstr,
  XINT	  *maxch, 
  XINT    *status
)
{
	register char	*ip, *op;
	register int	n;
	char	dirname[1025];
#ifdef POSIX
	char	*getcwd();
#else
	char	*getwd();
#endif

	/* If cwd is already known, just return the name.  Reconstructing
	 * the pathname of the cwd is expensive on some systems.
	 */
	if (oscwd[0] != EOS)
	    ip = oscwd;
	else {
#ifdef POSIX
	    ip = getcwd (dirname, 1024);
#else
	    ip = getwd (dirname);
#endif
	    if (ip == NULL) {
		*status = XERR;
		return (XERR);
	    } else
		strcpy (oscwd, dirname);
	}

	op = (char *)outstr;
	for (n = *maxch;  --n >= 0 && (*op = *ip++) != EOS;  )
	    op++;

	/* Make sure a concatenatable directory prefix is returned.
	 */
	if (*(op-1) != '/') {
	    *op++ = '/';
	    *op = EOS;
	}

	*status = op - (char *)outstr;

	return (*status);
}
Exemplo n.º 16
0
void
cinit(void)
{
	Sym *s;
	int i;

	nullgen.sym = S;
	nullgen.offset = 0;
	nullgen.type = D_NONE;
	nullgen.name = D_NONE;
	nullgen.reg = NREG;
	if(FPCHIP)
		nullgen.dval = 0;
	for(i=0; i<sizeof(nullgen.sval); i++)
		nullgen.sval[i] = 0;

	nerrors = 0;
	iostack = I;
	iofree = I;
	peekc = IGN;
	nhunk = 0;
	for(i=0; i<NHASH; i++)
		hash[i] = S;
	for(i=0; itab[i].name; i++) {
		s = slookup(itab[i].name);
		s->type = itab[i].type;
		s->value = itab[i].value;
	}

	ALLOCN(pathname, 0, 100);
	if(getwd(pathname, 99) == 0) {
		ALLOCN(pathname, 100, 900);
		if(getwd(pathname, 999) == 0)
			strcpy(pathname, "/???");
	}
}
Exemplo n.º 17
0
char *getcwd(char *buf, size_t size)
{
#ifndef MAXPATHLEN
#define	MAXPATHLEN	1024
#endif
	static char cwd[MAXPATHLEN];
	if (!getwd(cwd))
		return NULL;
	if (strlen(cwd) >= size) {
		errno = ERANGE;
		return NULL;
	}
	strcpy(buf, cwd);
	return 0;
}
Exemplo n.º 18
0
char *getcwd (char *buf, size_t len)
{
    char ourbuf[PATH_MAX];
    char *result;

    result = getwd (ourbuf);
    if (result) {
        if (strlen (ourbuf) >= len) {
            errno = ERANGE;
            return 0;
        }
        strcpy (buf, ourbuf);
    }
    return buf;
}
Exemplo n.º 19
0
/* getawd() is a substitute for getwd() which transforms the path */
static char *
getawd(char *path, size_t l)
{
#ifdef HAVE_GETCWD
  char *wd = getcwd(path, MAXPATHLEN);
#else /* not HAVE_GETCWD */
  char *wd = getwd(path);
#endif /* not HAVE_GETCWD */

  if (wd == NULL) {
    return NULL;
  }
  xstrlcpy(path, transform_dir(wd), l);
  return path;
}
Exemplo n.º 20
0
void
dwarf_init(char *iname)
{
	char buf[MAXPATHLEN];
	/*
	 * Setup sections.
	 * We'll print out the basic stuff early so that not
	 * so much context must be kept around.
	 */
	dwname = iname;
	debug_info_sz_lbl = dwlab();
	debug_abbrev_beg_lbl = dwlab();

	/* begin with setting up the compilation unit header */
	info412l(debug_info_sz_lbl); debug_info_sz = 0;
	info2w(DVERSION);
	info412l(debug_abbrev_beg_lbl);
	info1b(SZPOINT(VOID)/SZCHAR);

	/* Define abbrev table */
	dwslab(DABBREV, debug_abbrev_beg_lbl);

	/* compile unit follows, both in abbrev and info table */
	/* Recommended stuff here as in the documentation */
	al128(1); /* always first entry */
	al128(DW_TAG_compile_unit);
	al128(DW_CHILDREN_yes);

	apair(DW_AT_name, DW_FORM_strp); /* file name; e.g. foo.c */
	apair(DW_AT_producer, DW_FORM_string); /* producer; PCC 1.2.3 */
	apair(DW_AT_comp_dir, DW_FORM_string); /* working directory */
	apair(DW_AT_language, DW_FORM_data1); /* C99 */
	apair(DW_AT_low_pc, DW_FORM_addr); /* start text */
	apair(DW_AT_high_pc, DW_FORM_addr); /* end text */
	apair(0, 0);

	/* Above in info table */
	il128(1); /* first entry */
	ilbl(dwcfl = dwlab());
	istring(PACKAGE_STRING);
	istring(getwd(buf));
	il128(DW_LANG_C99);
	ilbl(dwbtext = dwlab());
	ilbl(dwetext = dwlab());

	locctr(PROG, NULL);
	printf(PRTPREF DLABEL ":\n", dwbtext);
}
Exemplo n.º 21
0
static void moveOkCb(Widget w, FileWindowRec *fw, XtPointer call_data)
{
  char path[MAXPATHLEN];

  XtPopdown(popups.move);
  fnSub(popups.move_s);

  if (chdir(popups.fw->directory) || chdir(popups.move_s))
    sysError("Can't change directory:");
  else if (!getwd(path))
    error("System error:", path);
  else {
    strcpy(popups.fw->directory, path);
    updateFileDisplay(popups.fw);
  }
}
Exemplo n.º 22
0
/* Return the supplied path with the current-working directory prefixed (if
 * needed) and all "dir/.." references removed.  Supply path_len if you want
 * to use only a substring of the path string, otherwise make it 0. */
char *dcc_abspath(const char *path, int path_len)
{
    static char buf[MAXPATHLEN];
    unsigned len;
    char *p, *slash;

    if (*path == '/')
        len = 0;
    else {
        char *ret;
#ifdef HAVE_GETCWD
        ret = getcwd(buf, sizeof buf);
        if (ret == NULL) {
          rs_log_crit("getcwd failed: %s", strerror(errno));
        }
#else
        ret = getwd(buf);
        if (ret == NULL) {
          rs_log_crit("getwd failed: %s", strerror(errno));
        }
#endif
        len = strlen(buf);
        if (len >= sizeof buf) {
            rs_log_crit("getwd overflowed in dcc_abspath()");
        }
        buf[len++] = '/';
    }
    if (path_len <= 0)
        path_len = strlen(path);
    if (path_len >= 2 && *path == '.' && path[1] == '/') {
        path += 2;
        path_len -= 2;
    }
    if (len + (unsigned)path_len >= sizeof buf) {
        rs_log_error("path overflowed in dcc_abspath()");
        exit(EXIT_OUT_OF_MEMORY);
    }
    strncpy(buf + len, path, path_len);
    buf[len + path_len] = '\0';
    for (p = buf+len-(len > 0); (p = strstr(p, "/../")) != NULL; p = slash) {
        *p = '\0';
        if (!(slash = strrchr(buf, '/')))
            slash = p;
        strcpy(slash, p+3);
    }
    return buf;
}
Exemplo n.º 23
0
char *SLpath_getcwd (void)
{
   char cwd[4096];
   char *p;
   size_t len;

#ifndef HAVE_GETCWD
   p = getwd (cwd);
#else
# if defined (__EMX__)
   p = _getcwd2(cwd, sizeof(cwd));	       /* includes drive specifier */
# else
   p = getcwd(cwd, sizeof(cwd));	       /* djggp includes drive specifier */
# endif
#endif

   if (p == NULL)
     return NULL;

#ifdef IBMPC_SYSTEM
   convert_slashes (cwd);
#endif

   len = strlen (cwd);

   p = (char *) SLmalloc (len+2);      /* \0 + trailing / */
   if (p == NULL)
     {
#ifdef ENOMEM
	errno = ENOMEM;
#endif
	return NULL;
     }

   strcpy (p, cwd);

#ifndef VMS
   if (len && (p[len-1] != PATH_SEP))
     {
	p[len++] = PATH_SEP;
	p[len] = 0;
     }
#endif

   return p;
}
Exemplo n.º 24
0
SpaceManager::SpaceManager () {
    Connection* c;
    char cwd[1024];
    int* tag;
    void* tmp;

    c = new Connection;
    if (!c->OpenLocalService(spaceman_mgr)) {
	fatal("can't connect to space manager");
    }
    chief = new ChiefDeputy(c);
    hostname[0] = '\0';
    chief->Alloc(tmp, chief->Tag(), 0, sizeof(int));
    tag = (int*)tmp;
    *tag = Tag();
    UsePath(getwd(cwd));
}
Exemplo n.º 25
0
void getUserNameLine(char* userLine) {
    userLine[0]='\0';
    struct passwd *psw;
    psw = getpwuid(getuid());
    strcat(userLine, psw->pw_name);
    strcat(userLine, "@");
    char hostName[MAXLINE];
    char wd[MAXLINE];
    getwd(wd);
    if(gethostname(hostName, sizeof(hostName)))
        return;
    else
        strcat(userLine, hostName);
    strcat(userLine, ":");
    strcat(userLine, wd);
    userType();
}
Exemplo n.º 26
0
void	ResetPath()
{
    if ( getwd(currentPath) == 0 )
    {
	fprintf(stderr, "Error getting pathname!!!\n");
	exit(1);
    }

    strcpy(&currentPath[strlen(currentPath)], "/");

    dfd = opendir(currentPath);
    if ( dfd == NULL )
    {
	fprintf(stderr, "can't open '%s'\n", currentPath);
	exit(1);
    }
}
Exemplo n.º 27
0
/**************************
 ReadFile()
 
 Opens the DVD data file and reads all
 of the DVD info it can.
 
 Each new DVDInfo struct is added to the
 linked list.
 */
void ReadFile( void )
{
	FILE *fp;
	
	if ( ( fp = fopen( kDVDFileName, "r" ) ) == NULL ) {
		printf( "Could not open file!\n" );
        printf( "File '%s' should be in %s.\n", kDVDFileName, getwd(NULL) );
		return;
	}
    
    struct DVDInfo *infoPtr;
    while ( ( infoPtr = ReadStructFromFile( fp ) ) != NULL ) {
        AddToList( infoPtr );
    }
	
	fclose( fp );
}
Exemplo n.º 28
0
int my_getwd(my_string buf, uint size, myf MyFlags)
{
  my_string pos;
  DBUG_ENTER("my_getwd");
  DBUG_PRINT("my",("buf: 0x%lx  size: %d  MyFlags %d", buf,size,MyFlags));

#if ! defined(MSDOS)
  if (curr_dir[0])				/* Current pos is saved here */
    VOID(strmake(buf,&curr_dir[0],size-1));
  else
#endif
  {
#if defined(HAVE_GETCWD)
    if (!getcwd(buf,size-2) && MyFlags & MY_WME)
    {
      my_errno=errno;
      my_error(EE_GETWD,MYF(ME_BELL+ME_WAITTANG),errno);
      return(-1);
    }
#elif defined(HAVE_GETWD)
    {
      char pathname[MAXPATHLEN];
      getwd(pathname);
      strmake(buf,pathname,size-1);
    }
#elif defined(VMS)
    if (!getcwd(buf,size-2,1) && MyFlags & MY_WME)
    {
      my_errno=errno;
      my_error(EE_GETWD,MYF(ME_BELL+ME_WAITTANG),errno);
      return(-1);
    }
    intern_filename(buf,buf);
#else
#error "No way to get current directory"
#endif
    if (*((pos=strend(buf))-1) != FN_LIBCHAR)  /* End with FN_LIBCHAR */
    {
      pos[0]= FN_LIBCHAR;
      pos[1]=0;
    }
    (void) strmake(&curr_dir[0],buf,(size_s) (FN_REFLEN-1));
  }
  DBUG_RETURN(0);
} /* my_getwd */
Exemplo n.º 29
0
/*@C
   PetscGetWorkingDirectory - Gets the current working directory.

   Not Collective

   Input Parameters:
.  len  - maximum length of path

   Output Parameter:
.  path - use to hold the result value. The string should be long enough
          to hold the path.

   Level: developer

   Concepts: working directory

@*/
PetscErrorCode PETSC_DLLEXPORT PetscGetWorkingDirectory(char path[],size_t len)
{
#if defined(PETSC_HAVE_GETCWD)
  PetscFunctionBegin;
  getcwd(path,len);
  PetscFunctionReturn(0);
#elif defined(PETSC_HAVE__GETCWD)
  PetscFunctionBegin;
  _getcwd(path,len);
  PetscFunctionReturn(0);
#elif defined(PETSC_HAVE_GETWD)
  PetscFunctionBegin;
  getwd(path);
  PetscFunctionReturn(0);
#else
  SETERRQ(PETSC_ERR_SUP_SYS, "Could not find getcwd() or getwd()");
#endif
}
Exemplo n.º 30
0
gchar*
g_get_current_dir (void)
{
  gchar *buffer = NULL;
  gchar *dir = NULL;
  static gulong max_len = (G_PATH_LENGTH == -1) ? 2048 : G_PATH_LENGTH;
  
  /* We don't use getcwd(3) on SUNOS, because, it does a popen("pwd")
   * and, if that wasn't bad enough, hangs in doing so.
   */
#if	defined (sun) && !defined (__SVR4)
  buffer = g_new (gchar, max_len + 1);
  *buffer = 0;
  dir = getwd (buffer);
#else	/* !sun */
  while (max_len < G_MAXULONG / 2)
    {
      buffer = g_new (gchar, max_len + 1);
      *buffer = 0;
      dir = getcwd (buffer, max_len);

      if (dir || errno != ERANGE)
	break;

      g_free (buffer);
      max_len *= 2;
    }
#endif	/* !sun */
  
  if (!dir || !*buffer)
    {
      /* hm, should we g_error() out here?
       * this can happen if e.g. "./" has mode \0000
       */
      buffer[0] = G_DIR_SEPARATOR;
      buffer[1] = 0;
    }

  dir = g_strdup (buffer);
  g_free (buffer);
  
  return dir;
}