1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
/*
* dosfile.cc: Part of GNU CSSC.
*
* Copyright (C) 1997,1998 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 2 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*
* CSSC was originally Based on MySC, by Ross Ridge, which was
* placed in the Public Domain.
*
*
* DOS-specific routines for accessing files.
*
*/
#include "cssc.h"
#include "sysdep.h"
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#include <stdio.h>
#ifdef CONFIG_USE_ARCHIVE_BIT
#ifdef CONFIG_NO__CHMOD
#include "_chmod.cc"
#ifndef FA_ARCH
#define FA_ARCH 0x20
#endif
#endif /* CONFIG_NO__CHMOD */
/* Clears the archive file attribute bit of a file. */
void
clear_archive_bit(const char *name) {
int attribs = _chmod(name, 0);
if (attribs == -1 || _chmod(name, 1, attribs & ~FA_ARCH) == -1) {
quit(errno, "%s: Can't clear archive file attribute.", name);
}
}
/* Returns true if the archive file attribute bit of a file is set. */
inline int
test_archive_bit(const char *name) {
int attribs = _chmod(name, 0);
if (attribs == -1) {
quit(errno, "%s: Can't test archive file attribute.", name);
}
return (attribs & FA_ARCH) == FA_ARCH;
}
#endif /* CONFIG_USE_ARCHIVE_BIT */
file_lock::file_lock(mystring zname): locked(0), name(zname) {
f = fcreate(zname, CREATE_WRITE_LOCK | CREATE_EXCLUSIVE);
if (f == NULL) {
struct DOSERROR err;
if (errno == EEXIST
|| (dosexterr(&err) == EACCES
&& err.de_class == 2 /* temporary situation */)) {
return;
}
quit(errno, "%s: Can't create lock file.",
zname.c_str());
}
if (fprintf(f, "%s\n", get_user_name()) < 0
|| fflush_failed(fflush(f)) || ffsync(f) == EOF) {
quit(errno, "%s: Write error.", zname.c_str());
}
locked = 1;
return;
}
file_lock::~file_lock() {
if (locked) {
locked = 0;
fclose(f);
unlink(name);
}
}
|