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 63 64 65 66 67 68 69 70 71 72 73 74
|
/*
* Copyright (C) 2000-2010 by CERN/IT/PDP/DM
* All rights reserved
*/
#ifndef lint
static char sccsid[] = "@(#)$RCSfile: nsdelcomment.c,v $ $Revision: 3581 $ $Date: 2010-05-27 09:48:26 +0200 (Thu, 27 May 2010) $ CERN IT-PDP/DM Jean-Philippe Baud";
#endif /* not lint */
/* nsdelcomment - delete a comment associated with a file/directory */
#include <errno.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#if defined(_WIN32)
#include <winsock2.h>
#endif
#include "Cns.h"
#include "Cns_api.h"
#include "serrno.h"
extern char *getenv();
main(argc, argv)
int argc;
char **argv;
{
int c;
int errflg = 0;
char fullpath[CA_MAXPATHLEN+1];
char *p;
char *path;
#if defined(_WIN32)
WSADATA wsadata;
#endif
if (argc != 2) {
fprintf (stderr,
"usage: %s file\n", argv[0]);
exit (USERR);
}
#if defined(_WIN32)
if (WSAStartup (MAKEWORD (2, 0), &wsadata)) {
fprintf (stderr, NS052);
exit (SYERR);
}
#endif
path = argv[1];
if (*path != '/' && strstr (path, ":/") == NULL) {
if ((p = getenv (CNS_HOME_ENV)) == NULL ||
strlen (p) + strlen (path) + 1 > CA_MAXPATHLEN) {
fprintf (stderr, "%s: invalid path\n", path);
errflg++;
} else
sprintf (fullpath, "%s/%s", p, path);
} else {
if (strlen (path) > CA_MAXPATHLEN) {
fprintf (stderr, "%s: %s\n", path,
sstrerror(SENAMETOOLONG));
errflg++;
} else
strcpy (fullpath, path);
}
if (errflg == 0 && Cns_delcomment (fullpath)) {
fprintf (stderr, "%s: %s\n", path, sstrerror(serrno));
errflg++;
}
#if defined(_WIN32)
WSACleanup();
#endif
if (errflg)
exit (USERR);
exit (0);
}
|