1/* $NetBSD$ */ 2 3/*++ 4/* NAME 5/* warn_stat 3 6/* SUMMARY 7/* baby-sit stat() error returns 8/* SYNOPSIS 9/* #include <warn_stat.h> 10/* 11/* int warn_stat(path, st) 12/* const char *path; 13/* struct stat *st; 14/* 15/* int warn_lstat(path, st) 16/* const char *path; 17/* struct stat *st; 18/* 19/* int warn_fstat(fd, st) 20/* int fd; 21/* struct stat *st; 22/* DESCRIPTION 23/* warn_stat(), warn_fstat() and warn_lstat() wrap the stat(), 24/* fstat() and lstat() system calls with code that logs a 25/* diagnosis for common error cases. 26/* LICENSE 27/* .ad 28/* .fi 29/* The Secure Mailer license must be distributed with this software. 30/* AUTHOR(S) 31/* Wietse Venema 32/* IBM T.J. Watson Research 33/* P.O. Box 704 34/* Yorktown Heights, NY 10598, USA 35/*--*/ 36 37/* System library. */ 38 39#include <sys_defs.h> 40#include <sys/stat.h> 41#include <errno.h> 42 43/* Utility library. */ 44 45#include <msg.h> 46#define WARN_STAT_INTERNAL 47#include <warn_stat.h> 48 49/* diagnose_stat - log stat warning */ 50 51static void diagnose_stat(void) 52{ 53 struct stat st; 54 55 /* 56 * When *stat() fails with EOVERFLOW, and the interface uses 32-bit data 57 * types, suggest that the program be recompiled with larger data types. 58 */ 59#ifdef EOVERFLOW 60 if (errno == EOVERFLOW && sizeof(st.st_size) == 4) { 61 msg_warn("this program was built for 32-bit file handles, " 62 "but some number does not fit in 32 bits"); 63 msg_warn("possible solution: recompile in 64-bit mode, or " 64 "recompile in 32-bit mode with 'large file' support"); 65 } 66#endif 67} 68 69/* warn_stat - stat with warning */ 70 71int warn_stat(const char *path, struct stat * st) 72{ 73 int ret; 74 75 ret = stat(path, st); 76 if (ret < 0) 77 diagnose_stat(); 78 return (ret); 79} 80 81/* warn_lstat - lstat with warning */ 82 83int warn_lstat(const char *path, struct stat * st) 84{ 85 int ret; 86 87 ret = lstat(path, st); 88 if (ret < 0) 89 diagnose_stat(); 90 return (ret); 91} 92 93/* warn_fstat - fstat with warning */ 94 95int warn_fstat(int fd, struct stat * st) 96{ 97 int ret; 98 99 ret = fstat(fd, st); 100 if (ret < 0) 101 diagnose_stat(); 102 return (ret); 103} 104