8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / oamuser / user / movedir.c
blobbad7a398ac7c568f7bd0dbc65b6b375aa2cf639d
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
24 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
28 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
29 /* All Rights Reserved */
32 #include <sys/types.h>
33 #include <stdio.h>
34 #include <userdefs.h>
35 #include "messages.h"
36 #include <unistd.h>
37 #include <sys/stat.h>
38 #include <utime.h>
40 #define SBUFSZ 256
42 extern int access(), rm_files();
44 static char cmdbuf[SBUFSZ]; /* buffer for system call */
47 * Move directory contents from one place to another
49 int
50 move_dir(char *from, char *to, char *login, int flags)
51 /* directory to move files from */
52 /* dirctory to move files to */
53 /* login id of owner */
54 /* miscellaneous flags */
56 size_t len = 0;
57 int rc = EX_SUCCESS;
58 struct stat statbuf;
59 struct utimbuf times;
61 * ***** THIS IS WHERE SUFFICIENT SPACE CHECK GOES
64 if (access(from, F_OK) == 0) { /* home dir exists */
65 /* move all files */
66 (void) sprintf(cmdbuf,
67 "cd %s && find . -print | cpio -m -pd %s",
68 from, to);
70 if (system(cmdbuf) != 0) {
71 errmsg(M_NOSPACE, from, to);
72 return (EX_NOSPACE);
76 * Check that to dir is not a subdirectory of from
78 len = strlen(from);
79 if (strncmp(from, to, len) == 0 &&
80 strncmp(to+len, "/", 1) == 0) {
81 errmsg(M_RMFILES);
82 return (EX_HOMEDIR);
84 /* Retain the original permission and modification time */
85 if (stat(from, &statbuf) == 0) {
86 chmod(to, statbuf.st_mode);
87 times.actime = statbuf.st_atime;
88 times.modtime = statbuf.st_mtime;
89 (void) utime(to, &times);
93 /* Remove the files in the old place */
94 rc = rm_files(from, login, flags);
98 return (rc);