File indexing completed on 2024-04-06 12:31:53
0001 #include "Utilities/StorageFactory/test/Test.h"
0002 #include "FWCore/Utilities/interface/Exception.h"
0003
0004 #include <errno.h>
0005 #include <iostream>
0006 #include <stdlib.h>
0007 #include <sys/stat.h>
0008 #include <sys/types.h>
0009 #include <unistd.h>
0010
0011 int main(int, char**) try {
0012 initTest();
0013 char pattern[] = "mkstemp-test-XXXXXX\0";
0014 struct stat status;
0015 mode_t previous_umask = umask(000);
0016 int fd = mkstemp(pattern);
0017 umask(previous_umask);
0018 if (fd == -1) {
0019 throw cms::Exception("TemporaryFile")
0020 << "Cannot create temporary file '" << pattern << "': " << strerror(errno) << " (error " << errno << ")";
0021 }
0022 int ret = fstat(fd, &status);
0023 unlink(pattern);
0024 if (ret != 0) {
0025 throw cms::Exception("TemporaryFile")
0026 << "Cannot fstat temporary file '" << pattern << "': " << strerror(errno) << " (error " << errno << ")";
0027 }
0028 mode_t mode = status.st_mode & 0777;
0029 if (mode != 0600) {
0030 throw cms::Exception("TemporaryFile") << "Temporary file '" << pattern << "': "
0031 << "created with mode " << std::oct << mode << " rather than 0600";
0032 }
0033 return EXIT_SUCCESS;
0034 } catch (cms::Exception const& e) {
0035 std::cerr << e.explainSelf() << std::endl;
0036 return EXIT_FAILURE;
0037 } catch (std::exception const& e) {
0038 std::cerr << e.what() << std::endl;
0039 return EXIT_FAILURE;
0040 }