X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=util.cc;h=0aa5efbb8eb521e14f935bc286de8c081067a62c;hb=78376bd08b8f19a73fde4a1d922c743bd0a9dfbf;hp=38f1f1dfa6357c43d8c44d8e915ac17528ca89c9;hpb=fbb042e3bbfe0796b0986fa0ffa9cde75c6e3bce;p=cumulus.git diff --git a/util.cc b/util.cc index 38f1f1d..0aa5efb 100644 --- a/util.cc +++ b/util.cc @@ -1,11 +1,30 @@ -/* LBS: An LFS-inspired filesystem backup system - * Copyright (C) 2007 Michael Vrable +/* Cumulus: Smart Filesystem Backup to Dumb Servers * - * Utility functions for converting various datatypes to text format (and - * later, for parsing them back, perhaps). + * Copyright (C) 2007 The Regents of the University of California + * Written by Michael Vrable + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +/* Utility functions for converting various datatypes to text format (and + * later, for parsing them back, perhaps). */ + #include +#include +#include +#include #include #include @@ -98,3 +117,21 @@ long long parse_int(const string &s) { return strtoll(s.c_str(), NULL, 0); } + +/* Mark a file descriptor as close-on-exec. */ +void cloexec(int fd) +{ + long flags = fcntl(fd, F_GETFD); + + if (flags < 0) + return; + + fcntl(fd, F_SETFD, flags | FD_CLOEXEC); +} + +/* Report a fatal error and exit. */ +void fatal(string msg) +{ + fprintf(stderr, "FATAL: %s\n", msg.c_str()); + exit(1); +}