Subject: __DATE__, __TIME__ Macros defined in wrong place, dd bug (#495) Index: src/bin/cc.c, src/lib/cpp/cpp.c, src/bin/dd.c Description: ANSI C macros __DATE__ and __TIME__ should be defined in cpp not cc. Patch 488 added these but various bits of documentation indicate that they are implemented by cpp. The cpp.1 man page file says so. Current Linux and BSD systems also implement the macros in the preprocessor. Also note that the macro __STDC_VERSION__ is not defined. Patch #492 added functionality to dd(1) but used a "signed long" integer in computatinos instead of "unsigned long". This causes dd to fail unexpectedly. Repeat-By: /lib/cpp <" __TIME__ __DATE__ Notice that /lib/cpp does not convert these macros into strings. Observe that __STDC_VERSION__ is not defined. Also inspect the file /usr/src/lib/cpp/cpp.c and notice that it contains a comment which says: /* set predefined symbols here (not from cc) */ dd bs=512 if=/unix of=/dev/null dd: argument 512 out of range Fix: Thanks to frank@wortner.com for the cc, cpp and dd patches. Cut where indicated and save to a file (/tmp/495.patch). Then: cd / patch -p0 < /tmp/495.patch cd /usr/src/lib/cpp make install make clean cd /usr/src/bin make cc dd install -s -m 0751 -o root -g staff cc dd /bin This and previous updates to 2.11BSD are available at the following locations: ftp://ftp.dfupdate.se/pub/pdp11/2.11BSD https://www.tuhs.org/Archive/Distributions/UCB/2.11BSD/Patches/ ftp://ftp.2bsd.com/2.11BSD http://www.2bsd.com/2.11BSD/ --------------------------cut here-------------------- *** ./usr/src/bin/cc.c.old Tue Mar 25 17:29:05 2025 --- ./usr/src/bin/cc.c Sat Aug 16 20:08:33 2025 *************** *** 1,5 **** #if !defined(lint) && defined(DOSCCS) ! static char sccsid[] = "@(#)cc.c 5.0 (2.11BSD) 2020/1/7"; #endif /* --- 1,5 ---- #if !defined(lint) && defined(DOSCCS) ! static char sccsid[] = "@(#)cc.c 5.1 (2.11BSD) 2025/8/16"; #endif /* *************** *** 20,28 **** char *ld = "/bin/ld"; char *crt0 = "/lib/crt0.o"; - char datebuf[26] = "-D__DATE__=\""; - char timebuf[26] = "-D__TIME__=\""; - char tmp0[30]; /* big enough for /tmp/ctm%05.5d */ char *tmp1, *tmp2, *tmp3, *tmp4, *tmp5; char *outfile; --- 20,25 ---- *************** *** 180,196 **** tmp4 = strspl(tmp0, "4"); if (oflag) tmp5 = strspl(tmp0, "5"); - - /* Create __TIME__ and __DATE__ as required by ISO C */ - tid = time(NULL); - ctbuf = ctime(&tid); - strncat(timebuf, &ctbuf[11], 8); - strcat(timebuf, "\""); - strncat(datebuf, &ctbuf[4], 7); - strncat(datebuf, &ctbuf[20], 4); - strcat(datebuf, "\""); - plist[np++] = timebuf; - plist[np++] = datebuf; for (i=0; i 1 && !Mflag) { --- 177,182 ---- *** ./usr/src/bin/dd.c.old Mon Aug 11 21:23:06 2025 --- ./usr/src/bin/dd.c Mon Aug 18 05:58:13 2025 *************** *** 1,5 **** #if !defined(lint) && defined(DOSCCS) ! static char *sccsid = "@(#)dd.c 5.0 (2.11BSD) 2025/8/11"; #endif #include --- 1,5 ---- #if !defined(lint) && defined(DOSCCS) ! static char *sccsid = "@(#)dd.c 5.1 (2.11BSD) 2025/8/18"; #endif #include *************** *** 169,175 **** register c; int ebcdic(), ibm(), ascii(), null(), cnull(), term(), stats(); int block(), unblock(); ! long number(); int a; conv = null; --- 169,175 ---- register c; int ebcdic(), ibm(), ascii(), null(), cnull(), term(), stats(); int block(), unblock(); ! unsigned long number(); int a; conv = null; *************** *** 478,489 **** return(1); } ! long number(big) unsigned long big; { register char *cs; ! long n; cs = string; n = 0; --- 478,489 ---- return(1); } ! unsigned long number(big) unsigned long big; { register char *cs; ! unsigned long n; cs = string; n = 0; *************** *** 510,516 **** n *= number(BIG); case '\0': ! if (n>=big || n<0) { fprintf(stderr, "dd: argument %D out of range\n", n); exit(1); } --- 510,516 ---- n *= number(BIG); case '\0': ! if (n>=big) { fprintf(stderr, "dd: argument %D out of range\n", n); exit(1); } *** ./usr/src/lib/cpp/cpp.c.old Tue Jan 7 13:49:02 2020 --- ./usr/src/lib/cpp/cpp.c Sun Aug 17 12:48:30 2025 *************** *** 1,7 **** /* $Id: cpp.c,v 1.311 2019/12/14 15:12:52 ragge Exp $ */ #if !defined(lint) && defined(DOSCCS) ! static char sccsid[] = "@(#)cpp.c 1.0 (2.11BSD) 2020/1/7"; #endif /* --- 1,7 ---- /* $Id: cpp.c,v 1.311 2019/12/14 15:12:52 ragge Exp $ */ #if !defined(lint) && defined(DOSCCS) ! static char sccsid[] = "@(#)cpp.c 1.1 (2.11BSD) 2025/8/16"; #endif /* *************** *** 183,188 **** --- 183,191 ---- register int ch; register const usch *fn1, *fn2; char *a; + time_t t; + char timebuf[12], datebuf[12]; + char *timestring; #ifdef TIMING struct timeval t1, t2; *************** *** 190,195 **** --- 193,201 ---- (void)gettimeofday(&t1, NULL); #endif + timebuf[0] = '\0'; + datebuf[0] = '\0'; + #if LIBVMF if (vminit(NVMPGS)) error("vminit"); *************** *** 336,344 **** bsheap(fb, "#define pdp11 1\n"); bsheap(fb, "#define unix 1\n"); /* XXX go away */ addidir("/usr/include", &incdir[SYSINC]); - if (tflag == 0) - bsheap(fb, "#define __STDC__ 1\n"); #endif macsav(0); filloc->valoff = linloc->valoff = pragloc->valoff = --- 342,363 ---- bsheap(fb, "#define pdp11 1\n"); bsheap(fb, "#define unix 1\n"); /* XXX go away */ addidir("/usr/include", &incdir[SYSINC]); #endif + + if (tflag == 0) + { + /* Create __TIME__ and __DATE__ as required by ANSI C */ + t = time(NULL); + timestring = ctime(&t); + /* ctime() string is a fixed size so we can "cheat" by using fixed offsets */ + strncat(timebuf, ×tring[11], 8); + strncat(datebuf, ×tring[4], 7); + strncat(datebuf, ×tring[20], 4); + bsheap(fb, "#define __DATE__ \"%s\"\n", datebuf); + bsheap(fb, "#define __TIME__ \"%s\"\n", timebuf); + bsheap(fb, "#define __STDC__ 1\n"); + bsheap(fb, "#define __STDC_VERSION__ 199901L\n"); + } macsav(0); filloc->valoff = linloc->valoff = pragloc->valoff = *** ./VERSION.old Wed Aug 13 06:18:06 2025 --- ./VERSION Sat Aug 16 19:54:42 2025 *************** *** 1,5 **** ! Current Patch Level: 494 ! Date: August 13, 2025 2.11 BSD ============ --- 1,5 ---- ! Current Patch Level: 495 ! Date: August 18, 2025 2.11 BSD ============