ptg10805159
Appendix C Chapter 5 Solutions 911
restorethe modification time from the archive; instead, the modification time is
set to the time of extraction. In all cases withtar,the access time after extraction
will be the time of extraction.
In contrast,cpiosets the access time and the modification time to the time of
extraction. By default, it doesn’t try to set the modification time to the value on
the archive. The-moption tocpiohas it set both the access time and the
modification time to the value that was archived.
4.16 The kernel has no inherent limit on the depth of a directory tree. Nevertheless,
many commands will fail on pathnames that exceedPATH_MAX.The program
shown in FigureC.3 creates a directory tree that is 1,000 levels deep, with each
level being a 45-character name. We are able to create this structure on all
platforms; however, we cannot obtain the absolute pathname of the directory at
the 1,000th level usinggetcwdon all platforms. On Mac OS X 10.6.8, we can
never getgetcwdto succeed while in the directory at the end of this long path.
The program is able to retrieve the pathname on FreeBSD 8.0, Linux 3.2.0, and
Solaris 10, but we have to callreallocnumerous times to obtain a buffer that is
large enough. Running this program on Linux 3.2.0 gives us
$./a.out
getcwd failed, size = 4096: Numerical result out of range
getcwd failed, size = 4196: Numerical result out of range
... 418 morelines
getcwd failed, size = 45896: Numerical result out of range
getcwd failed, size = 45996: Numerical result out of range
length = 46004
the 46,004-byte pathname is printed here
We are not able to archive this directory,however,usingcpio.Itcomplains that
many of the filenames aretoo long. In fact, cpio is unable to archive this
directory on all four platforms. In contrast, we can archive this directory using
taron FreeBSD 8.0, Linux 3.2.0, and Mac OS X 10.6.8. However, we are unable to
extract the directory hierarchy from the archive on Linux 3.2.0.
4.17 The/devdirectory has write permissions turned off to prevent a normal user
from removing the filenames in the directory.This means that the unlink
attempt fails.
Chapter 5
5.2 Thefgetsfunction reads up through and including the next newlineoruntil the
buffer is full(leaving room, of course, for the terminating null).Also,fputs
writes everything in the buffer until it hits a null byte; it doesn’t carewhether a
newline is in the buffer.So, ifMAXLINEis too small, both functions still work;
they’rejust called moreoften than they would be if the buffer werelarger.
If either of these functions removed or added the newline (asgetsandputsdo),
we would have to ensurethat our buffer was big enough for the largest line.