190792Sgshapiro/* 2261363Sgshapiro * Copyright (c) 2000-2002 Proofpoint, Inc. and its suppliers. 390792Sgshapiro * All rights reserved. 490792Sgshapiro * 590792Sgshapiro * By using this file, you agree to the terms and conditions set 690792Sgshapiro * forth in the LICENSE file which can be found at the top level of 790792Sgshapiro * the sendmail distribution. 890792Sgshapiro */ 990792Sgshapiro 1090792Sgshapiro#include <sm/gen.h> 11266692SgshapiroSM_IDSTR(id, "@(#)$Id: t-types.c,v 1.19 2013-11-22 20:51:44 ca Exp $") 1290792Sgshapiro 1390792Sgshapiro#include <sm/limits.h> 1490792Sgshapiro#include <sm/io.h> 1590792Sgshapiro#include <sm/string.h> 1690792Sgshapiro#include <sm/test.h> 1790792Sgshapiro#include <sm/types.h> 1890792Sgshapiro 1990792Sgshapiroint 2090792Sgshapiromain(argc, argv) 2190792Sgshapiro int argc; 2290792Sgshapiro char **argv; 2390792Sgshapiro{ 2490792Sgshapiro LONGLONG_T ll; 2590792Sgshapiro LONGLONG_T volatile lt; 2690792Sgshapiro ULONGLONG_T ull; 2790792Sgshapiro char buf[128]; 2890792Sgshapiro char *r; 2990792Sgshapiro 3090792Sgshapiro sm_test_begin(argc, argv, "test standard integral types"); 3190792Sgshapiro 3290792Sgshapiro SM_TEST(sizeof(LONGLONG_T) == sizeof(ULONGLONG_T)); 3390792Sgshapiro 3490792Sgshapiro /* 3590792Sgshapiro ** sendmail assumes that ino_t, off_t and void* can be cast 3690792Sgshapiro ** to ULONGLONG_T without losing information. 3790792Sgshapiro */ 3890792Sgshapiro 3990792Sgshapiro if (!SM_TEST(sizeof(ino_t) <= sizeof(ULONGLONG_T)) || 4090792Sgshapiro !SM_TEST(sizeof(off_t) <= sizeof(ULONGLONG_T)) || 4190792Sgshapiro !SM_TEST(sizeof(void*) <= sizeof(ULONGLONG_T))) 4290792Sgshapiro { 4390792Sgshapiro (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, "\ 4490792SgshapiroYour C compiler appears to support a 64 bit integral type,\n\ 4590792Sgshapirobut libsm is not configured to use it. You will need to set\n\ 4690792Sgshapiroeither SM_CONF_LONGLONG or SM_CONF_QUAD_T to 1. See libsm/README\n\ 4790792Sgshapirofor more details.\n"); 4890792Sgshapiro } 4990792Sgshapiro 5090792Sgshapiro /* 5190792Sgshapiro ** Most compilers notice that LLONG_MIN - 1 generate an underflow. 5290792Sgshapiro ** Some compiler generate code that will use the 'X' status bit 5390792Sgshapiro ** in a CPU and hence (LLONG_MIN - 1 > LLONG_MIN) will be false. 5490792Sgshapiro ** So we have to decide whether we want compiler warnings or 5590792Sgshapiro ** a wrong test... 5690792Sgshapiro ** Question: where do we really need what this test tests? 5790792Sgshapiro */ 5890792Sgshapiro 5990792Sgshapiro#if SM_CONF_TEST_LLONG 6090792Sgshapiro ll = LLONG_MIN; 6190792Sgshapiro (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, "\ 6290792SgshapiroYour C compiler maybe issued a warning during compilation,\n\ 6390792Sgshapiroplease IGNORE the compiler warning!.\n"); 6490792Sgshapiro lt = LLONG_MIN - 1; 6590792Sgshapiro SM_TEST(lt > ll); 6690792Sgshapiro sm_snprintf(buf, sizeof(buf), "%llx", ll); 6790792Sgshapiro r = "0"; 6890792Sgshapiro if (!SM_TEST(buf[0] == '8') 6990792Sgshapiro || !SM_TEST(strspn(&buf[1], r) == sizeof(ll) * 2 - 1)) 7090792Sgshapiro { 7190792Sgshapiro (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, 7290792Sgshapiro "oops: LLONG_MIN=%s\n", buf); 7390792Sgshapiro } 7490792Sgshapiro 7590792Sgshapiro ll = LLONG_MAX; 7690792Sgshapiro lt = ll + 1; 7790792Sgshapiro SM_TEST(lt < ll); 7890792Sgshapiro sm_snprintf(buf, sizeof(buf), "%llx", ll); 7990792Sgshapiro r = "f"; 8090792Sgshapiro if (!SM_TEST(buf[0] == '7') 8190792Sgshapiro || !SM_TEST(strspn(&buf[1], r) == sizeof(ll) * 2 - 1)) 8290792Sgshapiro { 8390792Sgshapiro (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, 8490792Sgshapiro "oops: LLONG_MAX=%s\n", buf); 8590792Sgshapiro } 8690792Sgshapiro#endif /* SM_CONF_TEST_LLONG */ 8790792Sgshapiro 8890792Sgshapiro ull = ULLONG_MAX; 8990792Sgshapiro SM_TEST(ull + 1 == 0); 9090792Sgshapiro sm_snprintf(buf, sizeof(buf), "%llx", ull); 9190792Sgshapiro r = "f"; 9290792Sgshapiro SM_TEST(strspn(buf, r) == sizeof(ll) * 2); 9390792Sgshapiro 9490792Sgshapiro /* 9590792Sgshapiro ** If QUAD_MAX is defined by <limits.h> then quad_t is defined. 9690792Sgshapiro ** Make sure LONGLONG_T is at least as big as quad_t. 9790792Sgshapiro */ 9890792Sgshapiro#ifdef QUAD_MAX 9990792Sgshapiro SM_TEST(QUAD_MAX <= LLONG_MAX); 10090792Sgshapiro#endif 10190792Sgshapiro 10290792Sgshapiro return sm_test_end(); 10390792Sgshapiro} 104