mode_t default_mode(src_path)
struct stat st;
stat(src_path, &st);
if (st.st_mode & (S_IXUSR
For directories (-d), default 0755 regardless.
Students fail the install exercise in Exam 42 Rank 02 for predictable reasons. Avoid these:
Case A: Last argument is existing directory →
For each source, copy into dir/basename(source).
Case B: Two args only, second not a directory → copy source to target (may overwrite).
Copy algorithm (without external cp):
int fd_src = open(src, O_RDONLY);
int fd_dst = open(tmpname, O_WRONLY | O_CREAT | O_EXCL, 0600);
// read/write loop
close(fd_src); close(fd_dst);
fchmod(fd_dst, final_mode);
fchown(fd_dst, owner, group); // if given
utime(tmpname, &source_times); // if preserving
rename(tmpname, dest);
Creating the temp name: Use .install_tmp_XXXXXX with mkstemp(3) — but that’s a libc function; exam may forbid it. Do it manually: snprintf(tmp, PATH_MAX, "%s/.tmp_%d_%ld", dirname(dest), getpid(), time(NULL)).
When copying without -m, the destination should have the source file’s modification time. Use utime(2) after writing.
Open a terminal and type:
examshell
The first time, it may ask for your intra login and password. Then it will ask for the exam key (displayed on the intranet page).
Exam 42 Rank 02 Install May 2026
mode_t default_mode(src_path)
struct stat st;
stat(src_path, &st);
if (st.st_mode & (S_IXUSR
For directories (-d), default 0755 regardless.
Students fail the install exercise in Exam 42 Rank 02 for predictable reasons. Avoid these:
Case A: Last argument is existing directory →
For each source, copy into dir/basename(source). exam 42 rank 02 install
Case B: Two args only, second not a directory → copy source to target (may overwrite).
Copy algorithm (without external cp):
int fd_src = open(src, O_RDONLY);
int fd_dst = open(tmpname, O_WRONLY | O_CREAT | O_EXCL, 0600);
// read/write loop
close(fd_src); close(fd_dst);
fchmod(fd_dst, final_mode);
fchown(fd_dst, owner, group); // if given
utime(tmpname, &source_times); // if preserving
rename(tmpname, dest);
Creating the temp name: Use .install_tmp_XXXXXX with mkstemp(3) — but that’s a libc function; exam may forbid it. Do it manually: snprintf(tmp, PATH_MAX, "%s/.tmp_%d_%ld", dirname(dest), getpid(), time(NULL)).
When copying without -m, the destination should have the source file’s modification time. Use utime(2) after writing. For directories ( -d ), default 0755 regardless
Open a terminal and type:
examshell
The first time, it may ask for your intra login and password. Then it will ask for the exam key (displayed on the intranet page). Creating the temp name: Use