X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fmake-file.h;h=3861f35109af866978b5938d0bbc34389e6c059b;hb=24c5f7c629e68801492d7ca1766953a2a954a820;hp=88fa879b49b017a5070b301da13e59fe4573f8a6;hpb=dcf9b154cbcaa35c3d8459a201b77eec8bcb30bd;p=pspp diff --git a/src/data/make-file.h b/src/data/make-file.h index 88fa879b49..3861f35109 100644 --- a/src/data/make-file.h +++ b/src/data/make-file.h @@ -1,35 +1,50 @@ -/* PSPP - computes sample statistics. - Copyright (C) 2004 Free Software Foundation, Inc. - Written by Ben Pfaff . +/* PSPP - a program for statistical analysis. + Copyright (C) 2004, 2010 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 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 3 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. + 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., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. */ - -#ifndef MKFILE_H -#define MKFILE_H - - -/* Creates a temporary file and stores its name in *FILENAME and - a file descriptor for it in *FD. Returns success. Caller is - responsible for freeing *FILENAME. */ -int make_temp_file (int *fd, char **filename); - - -/* Creates a temporary file and stores its name in *FILENAME and - a file stream for it in *FP. Returns success. Caller is - responsible for freeing *FILENAME. */ -int make_unique_file_stream (FILE **fp, char **filename) ; + along with this program. If not, see . */ + +#ifndef MAKE_FILE_H +#define MAKE_FILE_H + +#include +#include +#include + +/* Prepares to atomically replace a (potentially) existing file + by a new file, by creating a temporary file with the given + PERMISSIONS bits in the same directory as *FILE_NAME. + + Special files are an exception: they are not atomically + replaced but simply opened for writing. + + If successful, stores the temporary file's name in *TMP_NAME + and a stream for it opened according to MODE (which should be + "w" or "wb") in *FP. Returns a ticket that can be used to + commit or abort the file replacement. If neither action has + yet been taken, program termination via signal will cause + *TMP_FILE to be unlinked. + + The caller is responsible for closing *FP, but *TMP_NAME is + owned by the callee. */ +struct replace_file *replace_file_start (const char *file_name, + const char *mode, mode_t permissions, + FILE **fp, char **tmp_name); + +/* Commits or aborts the replacement of a (potentially) existing + file by a new file, using the ticket returned by + replace_file_start. Returns success. */ +bool replace_file_commit (struct replace_file *); +bool replace_file_abort (struct replace_file *); #endif /* make-file.h */