1 /* PSPP - computes sample statistics.
2 Copyright (C) 2004 Free Software Foundation, Inc.
3 Author: John Darrington
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23 #include <sys/types.h>
37 enum PER {PER_RO, PER_RW};
39 int change_permissions(const char *filename, enum PER per);
42 /* Parses the PERMISSIONS command. */
44 cmd_permissions (void)
50 if (lex_match_id ("FILE"))
53 fn = strdup(ds_c_str(&tokstr));
54 lex_force_match(T_STRING);
59 if ( ! lex_match_id ("PERMISSIONS"))
64 if ( lex_match_id("READONLY"))
66 if ( ! change_permissions(fn, PER_RO ) )
69 else if ( lex_match_id("WRITEABLE"))
71 if ( ! change_permissions(fn, PER_RW ) )
76 msg(ME, _("Expecting %s or %s."), "WRITEABLE", "READONLY");
94 change_permissions(const char *filename, enum PER per)
101 msg (SE, _("This command not allowed when the SAFER option is set."));
106 if ( -1 == stat(filename, &buf) )
108 const int errnum = errno;
109 msg(ME,_("Cannot stat %s: %s"), filename, strerror(errnum));
114 mode = buf.st_mode | S_IWUSR ;
116 mode = buf.st_mode & ~( S_IWOTH | S_IWUSR | S_IWGRP );
118 if ( -1 == chmod(filename, mode))
121 const int errnum = errno;
122 msg(ME,_("Cannot change mode of %s: %s"), filename, strerror(errnum));