当前位置: 技术问答>linux和unix
100分求“根据目录与文件属性知识编写简单版本的程序chgrp ”
来源: 互联网 发布时间:2017-01-24
本文导语: 本帖最后由 jrz520014 于 2010-07-05 15:18:23 编辑 如题, 根据目录与文件属性知识编写简单版本的程序chgrp 急需,非常感谢。 T_T~~~ 还有,大虾们有UNIX、LINUX 环境下,chgrp 命令的C源代码。 | chgr...
根据目录与文件属性知识编写简单版本的程序chgrp
急需,非常感谢。
T_T~~~
还有,大虾们有UNIX、LINUX 环境下,chgrp 命令的C源代码。
|
chgrp属于coreutils包里的命令
下载地址 然后看看相关源码
http://ftp.gnu.org/gnu/coreutils/coreutils-8.5.tar.gz
解压之后chgrp的源码路径是
coreutils-8.5/src/chgrp.c
下载地址 然后看看相关源码
http://ftp.gnu.org/gnu/coreutils/coreutils-8.5.tar.gz
解压之后chgrp的源码路径是
coreutils-8.5/src/chgrp.c
/* chgrp -- change group ownership of files
Copyright (C) 1989-1991, 1995-2010 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see . */
/* Written by David MacKenzie . */
#include
#include
#include
#include
#include
#include "system.h"
#include "chown-core.h"
#include "error.h"
#include "fts_.h"
#include "group-member.h"
#include "quote.h"
#include "root-dev-ino.h"
#include "xstrtol.h"
/* The official name of this program (e.g., no `g' prefix). */
#define PROGRAM_NAME "chgrp"
#define AUTHORS
proper_name ("David MacKenzie"),
proper_name ("Jim Meyering")
#if ! HAVE_ENDGRENT
# define endgrent() ((void) 0)
#endif
/* The argument to the --reference option. Use the group ID of this file.
This file must exist. */
static char *reference_file;
/* For long options that have no equivalent short option, use a
non-character as a pseudo short option, starting with CHAR_MAX + 1. */
enum
{
DEREFERENCE_OPTION = CHAR_MAX + 1,
NO_PRESERVE_ROOT,
PRESERVE_ROOT,
REFERENCE_FILE_OPTION
};
static struct option const long_options[] =
{
{"recursive", no_argument, NULL, 'R'},
{"changes", no_argument, NULL, 'c'},
{"dereference", no_argument, NULL, DEREFERENCE_OPTION},
{"no-dereference", no_argument, NULL, 'h'},
{"no-preserve-root", no_argument, NULL, NO_PRESERVE_ROOT},
{"preserve-root", no_argument, NULL, PRESERVE_ROOT},
{"quiet", no_argument, NULL, 'f'},
{"silent", no_argument, NULL, 'f'},
{"reference", required_argument, NULL, REFERENCE_FILE_OPTION},
{"verbose", no_argument, NULL, 'v'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
{NULL, 0, NULL, 0}
};
/* Return the group ID of NAME, or -1 if no name was specified. */
static gid_t
parse_group (const char *name)
{
gid_t gid = -1;
if (*name)
{
struct group *grp = getgrnam (name);
if (grp)
gid = grp->gr_gid;
else
{
unsigned long int tmp;
if (! (xstrtoul (name, NULL, 10, &tmp, "") == LONGINT_OK
&& tmp