File: Cns_getcwd.c

package info (click to toggle)
lfc-postgres 1.7.4.7-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 13,676 kB
  • ctags: 10,779
  • sloc: ansic: 146,136; sh: 13,176; perl: 11,142; python: 5,529; cpp: 5,113; sql: 1,790; makefile: 861; fortran: 113
file content (62 lines) | stat: -rw-r--r-- 1,140 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
 * Copyright (C) 2001 by CERN/IT/PDP/DM
 * All rights reserved
 */

#ifndef lint
static char sccsid[] = "@(#)$RCSfile: Cns_getcwd.c,v $ $Revision: 1.1.1.1 $ $Date: 2001/06/03 06:59:41 $ CERN IT-PDP/DM Jean-Philippe Baud";
#endif /* not lint */

/*	Cns_getcwd - get current working directory */

#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include "Cns_api.h"
#include "Cns.h"
#include "serrno.h"

char DLL_DECL *
Cns_getcwd(char *buf, int size)
{
	int alloc = 0;
	char func[16];
	char path[CA_MAXPATHLEN+1];
	struct Cns_api_thread_info *thip;
 
	strcpy (func, "Cns_getcwd");
	if (Cns_apiinit (&thip))
		return (NULL);

	if (size <= 0) {
		serrno = EINVAL;
		return (NULL);
	}
	if (! *thip->server) {
		serrno = ENOENT;
		return (NULL);
	}
	if (! buf) {
		if ((buf = malloc (size)) == NULL) {
			serrno = ENOMEM;
			return (NULL);
		}
		alloc = 1;
	}
		

	if (Cns_getpath (thip->server, thip->cwd, path) < 0) {
		if (alloc)
			free (buf);
		return (NULL);
	}
	if (strlen (path) > (size - 1)) {
		serrno = ERANGE;
		if (alloc)
			free (buf);
		return (NULL);
	}
	strcpy (buf, path);
	return (buf);
}