File: Cns_closedir.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 (61 lines) | stat: -rw-r--r-- 1,260 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
/*
 * Copyright (C) 1999-2006 by CERN/IT/PDP/DM
 * All rights reserved
 */

#ifndef lint
static char sccsid[] = "@(#)$RCSfile: Cns_closedir.c,v $ $Revision: 1.4 $ $Date: 2006/08/01 12:41:12 $ CERN IT-PDP/DM Jean-Philippe Baud";
#endif /* not lint */

/*	Cns_closedir - free the Cns_DIR structure */

#include <errno.h>
#include <stdlib.h>
#include <sys/types.h>
#if defined(_WIN32)
#include <winsock2.h>
#else
#include <netinet/in.h>
#endif
#include "Cns_api.h"
#include "Cns.h"
#include "marshall.h"
#include "serrno.h"

int DLL_DECL
Cns_closedir(Cns_DIR *dirp)
{
	int i;
	struct Cns_rep_info *ir;
	int msglen;
	char *sbp;
	char sendbuf[REQBUFSZ];

	if (! dirp) {
		serrno = EFAULT;
		return (-1);
	}

	/* tell nsdaemon to free the thread */

	sbp = sendbuf;
	marshall_LONG (sbp, CNS_MAGIC);
	marshall_LONG (sbp, CNS_CLOSEDIR);
	msglen = 3 * LONGSIZE;
	marshall_LONG (sbp, msglen);
	(void) send2nsd (&dirp->dd_fd, NULL, sendbuf, msglen, NULL, 0);

	if (dirp->replicas) {	/* free previous replica information */
		ir = (struct Cns_rep_info *) dirp->replicas;
		for (i = 0; i < dirp->nbreplicas; i++) {
			free (ir->host);
			free (ir->sfn);
			ir++;
		}
		free (dirp->replicas);
		dirp->nbreplicas = 0;
		dirp->replicas = NULL;
	}
	free (dirp);
	return (0);
}