|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - downloadIndex: ┃ T b ┃
Length: 2195 (0x893) Types: TextFile Names: »backup.c«
└─⟦a0efdde77⟧ Bits:30001252 EUUGD11 Tape, 1987 Spring Conference Helsinki └─ ⟦this⟧ »EUUGD11/euug-87hel/sec8/mcp/src/backup.c«
/**************************************************************************\ * * * backup.c * * * * Before the account files are modified mcp back them up. THe files are * * backed up only once per mcp session; if you save-changes more than once * * the backups will still contain the files as they were when the mcp * * session started, NOT the result of the last save-changes. * * * \**************************************************************************/ #include <sys/file.h> #include <stdio.h> #include "sysdep.h" #include "mem.h" #include "save.h" static int BackedUp = 0; extern char *sprintf(); /* * Will only backup one file per call! Don't pass all of ModBits to this * routine at once. */ backup(flag) int flag; { char *old, *new; if (BackedUp & flag) return 1; switch (flag) { case AC: old = ACFILE; new = ACBAK; break; #ifdef SENDMAIL case AL: if (copyfile(ALBIND, ALBINDBAK) == 0) return 0; old = ALIASFILE; new = ALIASBAK; break; #endif case CS: old = CSFILE; new = CSBAK; break; case GR: old = GRPFILE; new = GRPBAK; break; case PW: old = PWDFILE; new = PWDBAK; break; case RG: old = RANGEFILE; new = RANGEBAK; break; case SG: old = SIGFILE; new = SIGBAK; break; case VG: old = VIGFILE; new = VIGBAK; break; default: break; } if (copyfile(old, new) != 0) { BackedUp |= flag; return 1; } return 0; } copyfile(from, to) char *from, *to; { char buf[BUFSIZ+1]; int n, fromfd, tofd; char errmsg[LONG_BUF]; if ((fromfd = open(from, O_RDONLY)) < 0) { perr(from); err2("copy %s -> %s failed", from, to); return 0; } if ((tofd = open(to, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) { perr(from); err2("copy %s -> %s failed", from, to); return 0; } while ((n = read(fromfd, buf, BUFSIZ)) > 0) if (write(tofd, buf, n) != n) { (void) sprintf(errmsg, "write of %d bytes to %s failed", n, to); perr(errmsg); err2("copy %s -> %s failed", from, to); } (void) close(fromfd); (void) close(tofd); return 1; }