head 1.54; access; symbols netbsd-10-0-RELEASE:1.53.2.1 netbsd-10-0-RC6:1.53.2.1 netbsd-10-0-RC5:1.53.2.1 netbsd-10-0-RC4:1.53.2.1 netbsd-10-0-RC3:1.53.2.1 netbsd-10-0-RC2:1.53.2.1 netbsd-10-0-RC1:1.53.2.1 netbsd-10:1.53.0.2 netbsd-10-base:1.53 netbsd-9-3-RELEASE:1.44 cjep_sun2x-base1:1.44 cjep_sun2x:1.44.0.18 cjep_sun2x-base:1.44 cjep_staticlib_x-base1:1.44 netbsd-9-2-RELEASE:1.44 cjep_staticlib_x:1.44.0.16 cjep_staticlib_x-base:1.44 netbsd-9-1-RELEASE:1.44 phil-wifi-20200421:1.44 phil-wifi-20200411:1.44 is-mlppp:1.44.0.14 is-mlppp-base:1.44 phil-wifi-20200406:1.44 netbsd-8-2-RELEASE:1.44 netbsd-9-0-RELEASE:1.44 netbsd-9-0-RC2:1.44 netbsd-9-0-RC1:1.44 phil-wifi-20191119:1.44 netbsd-9:1.44.0.12 netbsd-9-base:1.44 phil-wifi-20190609:1.44 netbsd-8-1-RELEASE:1.44 netbsd-8-1-RC1:1.44 pgoyette-compat-merge-20190127:1.44 pgoyette-compat-20190127:1.44 pgoyette-compat-20190118:1.44 pgoyette-compat-1226:1.44 pgoyette-compat-1126:1.44 pgoyette-compat-1020:1.44 pgoyette-compat-0930:1.44 pgoyette-compat-0906:1.44 netbsd-7-2-RELEASE:1.42 pgoyette-compat-0728:1.44 netbsd-8-0-RELEASE:1.44 phil-wifi:1.44.0.10 phil-wifi-base:1.44 pgoyette-compat-0625:1.44 netbsd-8-0-RC2:1.44 pgoyette-compat-0521:1.44 pgoyette-compat-0502:1.44 pgoyette-compat-0422:1.44 netbsd-8-0-RC1:1.44 pgoyette-compat-0415:1.44 pgoyette-compat-0407:1.44 pgoyette-compat-0330:1.44 pgoyette-compat-0322:1.44 pgoyette-compat-0315:1.44 netbsd-7-1-2-RELEASE:1.42 pgoyette-compat:1.44.0.8 pgoyette-compat-base:1.44 netbsd-7-1-1-RELEASE:1.42 matt-nb8-mediatek:1.44.0.6 matt-nb8-mediatek-base:1.44 perseant-stdc-iso10646:1.44.0.4 perseant-stdc-iso10646-base:1.44 netbsd-8:1.44.0.2 netbsd-8-base:1.44 prg-localcount2-base3:1.44 prg-localcount2-base2:1.43 prg-localcount2-base1:1.43 prg-localcount2:1.43.0.6 prg-localcount2-base:1.43 pgoyette-localcount-20170426:1.43 bouyer-socketcan-base1:1.43 pgoyette-localcount-20170320:1.43 netbsd-7-1:1.42.0.18 netbsd-7-1-RELEASE:1.42 netbsd-7-1-RC2:1.42 netbsd-7-nhusb-base-20170116:1.42 bouyer-socketcan:1.43.0.4 bouyer-socketcan-base:1.43 pgoyette-localcount-20170107:1.43 netbsd-7-1-RC1:1.42 pgoyette-localcount-20161104:1.43 netbsd-7-0-2-RELEASE:1.42 localcount-20160914:1.43 netbsd-7-nhusb:1.42.0.16 netbsd-7-nhusb-base:1.42 pgoyette-localcount-20160806:1.43 pgoyette-localcount-20160726:1.43 pgoyette-localcount:1.43.0.2 pgoyette-localcount-base:1.43 netbsd-7-0-1-RELEASE:1.42 netbsd-7-0:1.42.0.14 netbsd-7-0-RELEASE:1.42 netbsd-7-0-RC3:1.42 netbsd-7-0-RC2:1.42 netbsd-7-0-RC1:1.42 netbsd-5-2-3-RELEASE:1.36.26.1 netbsd-5-1-5-RELEASE:1.36.26.1 netbsd-6-0-6-RELEASE:1.40 netbsd-6-1-5-RELEASE:1.40 netbsd-7:1.42.0.12 netbsd-7-base:1.42 yamt-pagecache-base9:1.42 yamt-pagecache-tag8:1.40.2.1 netbsd-6-1-4-RELEASE:1.40 netbsd-6-0-5-RELEASE:1.40 tls-earlyentropy:1.42.0.10 tls-earlyentropy-base:1.42 riastradh-xf86-video-intel-2-7-1-pre-2-21-15:1.42 riastradh-drm2-base3:1.42 netbsd-6-1-3-RELEASE:1.40 netbsd-6-0-4-RELEASE:1.40 netbsd-5-2-2-RELEASE:1.36.26.1 netbsd-5-1-4-RELEASE:1.36.26.1 netbsd-6-1-2-RELEASE:1.40 netbsd-6-0-3-RELEASE:1.40 netbsd-5-2-1-RELEASE:1.36.26.1 netbsd-5-1-3-RELEASE:1.36.26.1 netbsd-6-1-1-RELEASE:1.40 riastradh-drm2-base2:1.42 riastradh-drm2-base1:1.42 riastradh-drm2:1.42.0.4 riastradh-drm2-base:1.42 netbsd-6-1:1.40.0.10 netbsd-6-0-2-RELEASE:1.40 netbsd-6-1-RELEASE:1.40 khorben-n900:1.42.0.8 netbsd-6-1-RC4:1.40 netbsd-6-1-RC3:1.40 agc-symver:1.42.0.6 agc-symver-base:1.42 netbsd-6-1-RC2:1.40 netbsd-6-1-RC1:1.40 yamt-pagecache-base8:1.42 netbsd-5-2:1.36.26.1.0.10 netbsd-6-0-1-RELEASE:1.40 yamt-pagecache-base7:1.42 netbsd-5-2-RELEASE:1.36.26.1 netbsd-5-2-RC1:1.36.26.1 matt-nb6-plus-nbase:1.40 yamt-pagecache-base6:1.42 netbsd-6-0:1.40.0.8 netbsd-6-0-RELEASE:1.40 netbsd-6-0-RC2:1.40 tls-maxphys:1.42.0.2 tls-maxphys-base:1.42 matt-nb6-plus:1.40.0.6 matt-nb6-plus-base:1.40 netbsd-6-0-RC1:1.40 yamt-pagecache-base5:1.40 yamt-pagecache-base4:1.40 netbsd-6:1.40.0.4 netbsd-6-base:1.40 netbsd-5-1-2-RELEASE:1.36.26.1 netbsd-5-1-1-RELEASE:1.36.26.1 yamt-pagecache-base3:1.40 yamt-pagecache-base2:1.40 yamt-pagecache:1.40.0.2 yamt-pagecache-base:1.40 cherry-xenmp:1.38.0.4 cherry-xenmp-base:1.38 bouyer-quota2-nbase:1.38 bouyer-quota2:1.38.0.2 bouyer-quota2-base:1.38 matt-mips64-premerge-20101231:1.38 matt-nb5-mips64-premerge-20101231:1.36.26.1 matt-nb5-pq3:1.36.26.1.0.8 matt-nb5-pq3-base:1.36.26.1 netbsd-5-1:1.36.26.1.0.6 netbsd-5-1-RELEASE:1.36.26.1 netbsd-5-1-RC4:1.36.26.1 matt-nb5-mips64-k15:1.36.26.1 netbsd-5-1-RC3:1.36.26.1 netbsd-5-1-RC2:1.36.26.1 netbsd-5-1-RC1:1.36.26.1 netbsd-5-0-2-RELEASE:1.36.26.1 matt-nb5-mips64-premerge-20091211:1.36.26.1 matt-premerge-20091211:1.38 matt-nb5-mips64-u2-k2-k4-k7-k8-k9:1.36.26.1 matt-nb4-mips64-k7-u2a-k9b:1.36.26.1 matt-nb5-mips64-u1-k1-k5:1.36.26.1 matt-nb5-mips64:1.36.26.1.0.4 netbsd-5-0-1-RELEASE:1.36.26.1 jym-xensuspend-nbase:1.38 netbsd-5-0:1.36.26.1.0.2 netbsd-5-0-RELEASE:1.36.26.1 netbsd-5-0-RC4:1.36.26.1 netbsd-5-0-RC3:1.36 netbsd-5-0-RC2:1.36 jym-xensuspend:1.37.0.2 jym-xensuspend-base:1.38 netbsd-5-0-RC1:1.36 netbsd-5:1.36.0.26 netbsd-5-base:1.36 matt-mips64-base2:1.36 matt-mips64:1.36.0.24 mjf-devfs2:1.36.0.22 mjf-devfs2-base:1.36 netbsd-4-0-1-RELEASE:1.36 wrstuden-revivesa-base-3:1.36 wrstuden-revivesa-base-2:1.36 wrstuden-fixsa-newbase:1.36 wrstuden-revivesa-base-1:1.36 yamt-pf42-base4:1.36 yamt-pf42-base3:1.36 hpcarm-cleanup-nbase:1.36 yamt-pf42-baseX:1.36 yamt-pf42-base2:1.36 wrstuden-revivesa:1.36.0.20 wrstuden-revivesa-base:1.36 yamt-pf42:1.36.0.18 yamt-pf42-base:1.36 keiichi-mipv6:1.36.0.16 keiichi-mipv6-base:1.36 matt-armv6-nbase:1.36 matt-armv6-prevmlocking:1.36 wrstuden-fixsa-base-1:1.36 netbsd-4-0:1.36.0.14 netbsd-4-0-RELEASE:1.36 cube-autoconf:1.36.0.12 cube-autoconf-base:1.36 netbsd-4-0-RC5:1.36 netbsd-4-0-RC4:1.36 netbsd-4-0-RC3:1.36 netbsd-4-0-RC2:1.36 netbsd-4-0-RC1:1.36 matt-armv6:1.36.0.10 matt-armv6-base:1.36 matt-mips64-base:1.36 hpcarm-cleanup:1.36.0.8 hpcarm-cleanup-base:1.36 netbsd-3-1-1-RELEASE:1.34.2.1 netbsd-3-0-3-RELEASE:1.34.2.1 wrstuden-fixsa:1.36.0.6 wrstuden-fixsa-base:1.36 abandoned-netbsd-4-base:1.36 abandoned-netbsd-4:1.36.0.2 netbsd-3-1:1.34.2.1.0.4 netbsd-3-1-RELEASE:1.34.2.1 netbsd-3-0-2-RELEASE:1.34.2.1 netbsd-3-1-RC4:1.34.2.1 netbsd-3-1-RC3:1.34.2.1 netbsd-3-1-RC2:1.34.2.1 netbsd-3-1-RC1:1.34.2.1 netbsd-4:1.36.0.4 netbsd-4-base:1.36 netbsd-3-0-1-RELEASE:1.34.2.1 netbsd-3-0:1.34.2.1.0.2 netbsd-3-0-RELEASE:1.34.2.1 netbsd-3-0-RC6:1.34.2.1 netbsd-3-0-RC5:1.34.2.1 netbsd-3-0-RC4:1.34.2.1 netbsd-3-0-RC3:1.34.2.1 netbsd-3-0-RC2:1.34.2.1 netbsd-3-0-RC1:1.34.2.1 netbsd-2-0-3-RELEASE:1.32 netbsd-2-1:1.32.0.6 netbsd-2-1-RELEASE:1.32 netbsd-2-1-RC6:1.32 netbsd-2-1-RC5:1.32 netbsd-2-1-RC4:1.32 netbsd-2-1-RC3:1.32 netbsd-2-1-RC2:1.32 netbsd-2-1-RC1:1.32 netbsd-2-0-2-RELEASE:1.32 netbsd-3:1.34.0.2 netbsd-3-base:1.34 netbsd-2-0-1-RELEASE:1.32 netbsd-2:1.32.0.4 netbsd-2-base:1.32 netbsd-2-0-RELEASE:1.32 netbsd-2-0-RC5:1.32 netbsd-2-0-RC4:1.32 netbsd-2-0-RC3:1.32 netbsd-2-0-RC2:1.32 netbsd-2-0-RC1:1.32 netbsd-2-0:1.32.0.2 netbsd-2-0-base:1.32 netbsd-1-6-PATCH002-RELEASE:1.30 netbsd-1-6-PATCH002:1.30 netbsd-1-6-PATCH002-RC4:1.30 netbsd-1-6-PATCH002-RC3:1.30 netbsd-1-6-PATCH002-RC2:1.30 netbsd-1-6-PATCH002-RC1:1.30 netbsd-1-6-PATCH001:1.30 netbsd-1-6-PATCH001-RELEASE:1.30 netbsd-1-6-PATCH001-RC3:1.30 netbsd-1-6-PATCH001-RC2:1.30 netbsd-1-6-PATCH001-RC1:1.30 fvdl_fs64_base:1.31 netbsd-1-6-RELEASE:1.30 netbsd-1-6-RC3:1.30 netbsd-1-6-RC2:1.30 netbsd-1-6-RC1:1.30 netbsd-1-6:1.30.0.4 netbsd-1-6-base:1.30 netbsd-1-5-PATCH003:1.27 ELRICshvfork:1.30.0.2 ELRICshvfork-base:1.30 netbsd-1-5-PATCH002:1.27 netbsd-1-5-PATCH001:1.27 netbsd-1-5-RELEASE:1.27 netbsd-1-5-BETA2:1.27 netbsd-1-5-BETA:1.27 netbsd-1-4-PATCH003:1.27 netbsd-1-5-ALPHA2:1.27 netbsd-1-5:1.27.0.10 netbsd-1-5-base:1.27 minoura-xpg4dl:1.27.0.8 minoura-xpg4dl-base:1.27 netbsd-1-4-PATCH002:1.27 wrstuden-devbsize-19991221:1.27 wrstuden-devbsize:1.27.0.6 wrstuden-devbsize-base:1.27 comdex-fall-1999:1.27.0.4 comdex-fall-1999-base:1.27 netbsd-1-4-PATCH001:1.27 netbsd-1-4-RELEASE:1.27 netbsd-1-4:1.27.0.2 netbsd-1-4-base:1.27 netbsd-1-3-PATCH003:1.19.2.2 netbsd-1-3-PATCH003-CANDIDATE2:1.19.2.2 netbsd-1-3-PATCH003-CANDIDATE1:1.19.2.2 netbsd-1-3-PATCH003-CANDIDATE0:1.19.2.2 netbsd-1-3-PATCH002:1.19.2.2 netbsd-1-3-PATCH001:1.19.2.1 netbsd-1-3-RELEASE:1.19.2.1 netbsd-1-3-BETA:1.19.2.1 netbsd-1-3:1.19.0.2 netbsd-1-3-base:1.19 netbsd-1-2-PATCH001:1.15.6.1 netbsd-1-2-RELEASE:1.15 netbsd-1-2-BETA:1.15 netbsd-1-2-base:1.15 netbsd-1-2:1.15.0.6 netbsd-1-1-PATCH001:1.15 netbsd-1-1-RELEASE:1.15 netbsd-1-1:1.15.0.2 netbsd-1-1-base:1.15 netbsd-1-0-PATCH06:1.11 netbsd-1-0-PATCH05:1.11 netbsd-1-0-PATCH04:1.11 netbsd-1-0-PATCH03:1.11 netbsd-1-0-PATCH02:1.11 netbsd-1-0-PATCH1:1.11 netbsd-1-0-PATCH0:1.11 netbsd-1-0-RELEASE:1.11 netbsd-1-0:1.11.0.2 netbsd-1-0-base:1.11 lite-1:1.1.1.2 CSRG:1.1.1 netbsd-0-9-RELEASE:1.3 netbsd-0-9-BETA:1.3 netbsd-0-9-ALPHA2:1.3 netbsd-0-9-ALPHA:1.3 netbsd-0-9:1.3.0.2 netbsd-0-9-base:1.3 netbsd-0-8:1.3 netbsd-alpha-1:1.3 patchkit-0-2-2:1.1.1.1 WFJ-386bsd-01:1.1.1.1 WFJ-920714:1.1.1; locks; strict; comment @ * @; 1.54 date 2023.10.05.20.33.31; author kre; state Exp; branches; next 1.53; commitid wSgyez4CqCdAGtHE; 1.53 date 2022.12.11.08.23.10; author kre; state Exp; branches 1.53.2.1; next 1.52; commitid WbSH98SUFUG5c75E; 1.52 date 2022.08.19.12.52.31; author kre; state Exp; branches; next 1.51; commitid 9pKE8Utv2fPvnuQD; 1.51 date 2022.08.19.12.17.18; author kre; state Exp; branches; next 1.50; commitid aqRV1Pmy32gqbuQD; 1.50 date 2022.04.16.14.26.26; author kre; state Exp; branches; next 1.49; commitid rJqQ8mUUO6ZPUqAD; 1.49 date 2022.04.16.14.23.36; author kre; state Exp; branches; next 1.48; commitid Mi8j5m8Js8GRTqAD; 1.48 date 2022.04.16.14.20.45; author kre; state Exp; branches; next 1.47; commitid EJisUTP13uHSSqAD; 1.47 date 2021.12.12.11.18.46; author andvar; state Exp; branches; next 1.46; commitid KErdv2IfqNrxSlkD; 1.46 date 2021.11.16.11.27.50; author kre; state Exp; branches; next 1.45; commitid r0Si718YHEyuM0hD; 1.45 date 2021.09.15.18.30.57; author kre; state Exp; branches; next 1.44; commitid F7alOlrt1cec759D; 1.44 date 2017.05.13.15.03.34; author gson; state Exp; branches 1.44.2.1 1.44.10.1 1.44.12.1; next 1.43; commitid GQjnv96uq1aOWeRz; 1.43 date 2015.05.09.13.28.55; author christos; state Exp; branches 1.43.6.1; next 1.42; commitid qZStTwtnbhv23Mky; 1.42 date 2012.06.11.18.28.10; author njoly; state Exp; branches; next 1.41; 1.41 date 2012.06.09.02.49.48; author christos; state Exp; branches; next 1.40; 1.40 date 2011.10.11.15.27.11; author christos; state Exp; branches 1.40.2.1; next 1.39; 1.39 date 2011.06.18.21.18.46; author christos; state Exp; branches; next 1.38; 1.38 date 2009.03.29.01.02.49; author mrg; state Exp; branches 1.38.4.1; next 1.37; 1.37 date 2008.12.28.19.53.37; author christos; state Exp; branches 1.37.2.1; next 1.36; 1.36 date 2005.10.01.20.23.54; author christos; state Exp; branches 1.36.26.1; next 1.35; 1.35 date 2005.03.19.14.22.50; author dsl; state Exp; branches; next 1.34; 1.34 date 2004.04.19.01.36.32; author lukem; state Exp; branches 1.34.2.1; next 1.33; 1.33 date 2004.04.17.15.41.29; author christos; state Exp; branches; next 1.32; 1.32 date 2003.08.07.09.05.35; author agc; state Exp; branches; next 1.31; 1.31 date 2002.11.24.22.35.41; author christos; state Exp; branches; next 1.30; 1.30 date 2001.02.04.19.52.06; author christos; state Exp; branches; next 1.29; 1.29 date 2001.01.04.15.39.51; author lukem; state Exp; branches; next 1.28; 1.28 date 2000.11.22.19.20.31; author christos; state Exp; branches; next 1.27; 1.27 date 98.09.26.19.28.12; author christos; state Exp; branches; next 1.26; 1.26 date 98.09.24.17.49.48; author itohy; state Exp; branches; next 1.25; 1.25 date 98.05.20.00.32.05; author christos; state Exp; branches; next 1.24; 1.24 date 98.02.04.20.10.17; author thorpej; state Exp; branches; next 1.23; 1.23 date 98.01.21.10.47.39; author christos; state Exp; branches; next 1.22; 1.22 date 98.01.16.16.26.22; author christos; state Exp; branches; next 1.21; 1.21 date 98.01.15.19.39.11; author christos; state Exp; branches; next 1.20; 1.20 date 97.11.05.14.05.28; author kleink; state Exp; branches; next 1.19; 1.19 date 97.07.04.21.02.09; author christos; state Exp; branches 1.19.2.1; next 1.18; 1.18 date 97.04.11.23.08.15; author christos; state Exp; branches; next 1.17; 1.17 date 97.01.11.02.04.38; author tls; state Exp; branches; next 1.16; 1.16 date 96.10.16.15.45.11; author christos; state Exp; branches; next 1.15; 1.15 date 95.06.12.19.44.16; author jtc; state Exp; branches 1.15.6.1; next 1.14; 1.14 date 95.05.11.21.29.32; author christos; state Exp; branches; next 1.13; 1.13 date 95.03.21.09.09.33; author cgd; state Exp; branches; next 1.12; 1.12 date 94.12.05.19.07.45; author cgd; state Exp; branches; next 1.11; 1.11 date 94.06.11.16.12.11; author mycroft; state Exp; branches; next 1.10; 1.10 date 94.05.12.17.08.56; author jtc; state Exp; branches; next 1.9; 1.9 date 94.05.12.17.03.45; author jtc; state Exp; branches; next 1.8; 1.8 date 94.05.11.17.53.54; author jtc; state Exp; branches; next 1.7; 1.7 date 94.05.11.17.10.18; author jtc; state Exp; branches; next 1.6; 1.6 date 94.04.06.19.08.14; author cgd; state Exp; branches; next 1.5; 1.5 date 93.08.01.18.57.56; author mycroft; state Exp; branches; next 1.4; 1.4 date 93.07.21.00.02.33; author jtc; state Exp; branches; next 1.3; 1.3 date 93.03.23.00.28.32; author cgd; state Exp; branches; next 1.2; 1.2 date 93.03.22.08.04.00; author cgd; state Exp; branches; next 1.1; 1.1 date 93.03.21.09.45.37; author cgd; state Exp; branches 1.1.1.1; next ; 1.53.2.1 date 2023.11.03.10.07.09; author martin; state Exp; branches; next ; commitid iQHvVNWFNniUh9LE; 1.44.2.1 date 2022.10.27.16.16.50; author martin; state Exp; branches; next ; commitid EyF1AHFcp9m5inZD; 1.44.10.1 date 2020.04.21.18.41.06; author martin; state dead; branches; next 1.44.10.2; commitid 86tA4aEmdr3VCh5C; 1.44.10.2 date 2020.04.21.19.37.34; author martin; state Exp; branches; next ; commitid x6IB64bYH9UmWh5C; 1.44.12.1 date 2022.10.27.16.14.42; author martin; state Exp; branches; next ; commitid 6mAK5j7A2H9mhnZD; 1.43.6.1 date 2017.05.19.00.22.51; author pgoyette; state Exp; branches; next ; commitid QNTxgGjVagwoSVRz; 1.40.2.1 date 2012.10.30.18.46.08; author yamt; state Exp; branches; next ; 1.38.4.1 date 2011.06.23.14.17.48; author cherry; state Exp; branches; next ; 1.37.2.1 date 2009.05.13.19.15.51; author jym; state Exp; branches; next ; 1.36.26.1 date 2009.04.01.00.25.21; author snj; state Exp; branches; next ; 1.34.2.1 date 2005.04.07.11.34.20; author tron; state Exp; branches; next ; 1.19.2.1 date 97.11.06.07.00.17; author mellon; state Exp; branches; next 1.19.2.2; 1.19.2.2 date 98.05.08.06.01.04; author mycroft; state Exp; branches; next ; 1.15.6.1 date 97.01.26.04.57.26; author rat; state Exp; branches; next ; 1.1.1.1 date 93.03.21.09.45.37; author cgd; state Exp; branches; next 1.1.1.2; 1.1.1.2 date 94.05.11.17.01.32; author jtc; state Exp; branches; next ; desc @@ 1.54 log @If the read builtin is told to read into IFS, we must avoid doing that until all current uses of IFS are complete (as we have IFS's value cached in ifs - if IFS alters, ifs might point anywhere). Handle this by deferring assignments to IFS until everything is done. This makes us appear to comply with the (currently) proposed requirement for read by POSIX that field splitting complete before vars are assigned. (Other shells, like dash, ksh93, yash, bosh behave like this) That might end up being unspecified though, as other shells (bosh, mksh) assign each field to its var as it is delimited (though bosh appears to have bugs). If we wanted to go that route, the issue here could have been handled by re-doing the init of ifs after every setvar() that is performed here (except the last, after which it is no longer needed). XXX pullup -10 @ text @/* $NetBSD: miscbltin.c,v 1.53 2022/12/11 08:23:10 kre Exp $ */ /*- * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Kenneth Almquist. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #ifndef lint #if 0 static char sccsid[] = "@@(#)miscbltin.c 8.4 (Berkeley) 5/4/95"; #else __RCSID("$NetBSD: miscbltin.c,v 1.53 2022/12/11 08:23:10 kre Exp $"); #endif #endif /* not lint */ /* * Miscellaneous builtins. */ #include /* quad_t */ #include /* BSD4_4 */ #include #include #include #include #include #include #include #include "shell.h" #include "options.h" #include "var.h" #include "output.h" #include "memalloc.h" #include "error.h" #include "builtins.h" #include "mystring.h" #include "redir.h" /* for user_fd_limit */ #undef rflag /* * The read builtin. * Backslashes escape the next char unless -r is specified. * * This uses unbuffered input, which may be avoidable in some cases. * * Note that if IFS=' :' then read x y should work so that: * 'a b' x='a', y='b' * ' a b ' x='a', y='b' * ':b' x='', y='b' * ':' x='', y='' * '::' x='', y='' * ': :' x='', y='' * ':::' x='', y='::' * ':b c:' x='', y='b c:' */ int readcmd(int argc, char **argv) { char **ap; char c; char end; int rflag; char *prompt; const char *ifs; char *p; int startword; int status; int i; int is_ifs; int saveall = 0; ptrdiff_t wordlen = 0; char *newifs = NULL; struct stackmark mk; end = '\n'; /* record delimiter */ rflag = 0; prompt = NULL; while ((i = nextopt("d:p:r")) != '\0') { switch (i) { case 'd': end = *optionarg; /* even if '\0' */ break; case 'p': prompt = optionarg; break; case 'r': rflag = 1; break; } } if (*(ap = argptr) == NULL) error("variable name required\n" "Usage: read [-r] [-p prompt] var..."); if (prompt && isatty(0)) { out2str(prompt); flushall(); } if ((ifs = bltinlookup("IFS", 1)) == NULL) ifs = " \t\n"; setstackmark(&mk); status = 0; startword = 2; STARTSTACKSTR(p); for (;;) { if (read(0, &c, 1) != 1) { status = 1; break; } if (c == '\\' && c != end && !rflag) { if (read(0, &c, 1) != 1) { status = 1; break; } if (c != '\n') /* \ \n is always just removed */ goto wdch; continue; } if (c == end) break; if (c == '\0') continue; if (strchr(ifs, c)) is_ifs = strchr(" \t\n", c) ? 1 : 2; else is_ifs = 0; if (startword != 0) { if (is_ifs == 1) { /* Ignore leading IFS whitespace */ if (saveall) STPUTC(c, p); continue; } if (is_ifs == 2 && startword == 1) { /* Only one non-whitespace IFS per word */ startword = 2; if (saveall) STPUTC(c, p); continue; } } if (is_ifs == 0) { wdch:; if (c == '\0') /* always ignore attempts to input \0 */ continue; /* append this character to the current variable */ startword = 0; if (saveall) /* Not just a spare terminator */ saveall++; STPUTC(c, p); wordlen = p - stackblock(); continue; } /* end of variable... */ startword = is_ifs; if (ap[1] == NULL) { /* Last variable needs all IFS chars */ saveall++; STPUTC(c, p); continue; } if (equal(*ap, "IFS")) { /* * we must not alter the value of IFS, as our * local "ifs" var is (perhaps) pointing at it, * at best we would be using data after free() * the next time we reference ifs - but that mem * may have been reused for something different. * * note that this might occur several times */ STPUTC('\0', p); newifs = grabstackstr(p); } else { STACKSTRNUL(p); setvar(*ap, stackblock(), 0); } ap++; STARTSTACKSTR(p); wordlen = 0; } STACKSTRNUL(p); /* Remove trailing IFS chars */ for (; stackblock() + wordlen <= --p; *p = 0) { if (!strchr(ifs, *p)) break; if (strchr(" \t\n", *p)) /* Always remove whitespace */ continue; if (saveall > 1) /* Don't remove non-whitespace unless it was naked */ break; } /* * If IFS was one of the variables named, we can finally set it now * (no further references to ifs will be made) */ if (newifs != NULL) setvar("IFS", newifs, 0); /* * Now we can assign to the final variable (which might * also be IFS, hence the ordering here) */ setvar(*ap, stackblock(), 0); /* Set any remaining args to "" */ while (*++ap != NULL) setvar(*ap, nullstr, 0); popstackmark(&mk); return status; } int umaskcmd(int argc, char **argv) { char *ap; mode_t mask; int i; int symbolic_mode = 0; while ((i = nextopt("S")) != '\0') { symbolic_mode = 1; } INTOFF; mask = umask(0); umask(mask); INTON; if ((ap = *argptr) == NULL) { if (symbolic_mode) { char u[4], g[4], o[4]; i = 0; if ((mask & S_IRUSR) == 0) u[i++] = 'r'; if ((mask & S_IWUSR) == 0) u[i++] = 'w'; if ((mask & S_IXUSR) == 0) u[i++] = 'x'; u[i] = '\0'; i = 0; if ((mask & S_IRGRP) == 0) g[i++] = 'r'; if ((mask & S_IWGRP) == 0) g[i++] = 'w'; if ((mask & S_IXGRP) == 0) g[i++] = 'x'; g[i] = '\0'; i = 0; if ((mask & S_IROTH) == 0) o[i++] = 'r'; if ((mask & S_IWOTH) == 0) o[i++] = 'w'; if ((mask & S_IXOTH) == 0) o[i++] = 'x'; o[i] = '\0'; out1fmt("u=%s,g=%s,o=%s\n", u, g, o); } else { out1fmt("%.4o\n", mask); } } else { if (isdigit((unsigned char)*ap)) { int range = 0; mask = 0; do { if (*ap >= '8' || *ap < '0') error("Not a valid octal number: '%s'", *argptr); mask = (mask << 3) + (*ap - '0'); if (mask & ~07777) range = 1; } while (*++ap != '\0'); if (range) error("Mask constant '%s' out of range", *argptr); umask(mask); } else { void *set; INTOFF; if ((set = setmode(ap)) != 0) { mask = getmode(set, ~mask & 0777); ckfree(set); } INTON; if (!set) error("Cannot set mode `%s' (%s)", ap, strerror(errno)); umask(~mask & 0777); } } flushout(out1); if (io_err(out1)) { out2str("umask: I/O error\n"); return 1; } return 0; } /* * ulimit builtin * * This code, originally by Doug Gwyn, Doug Kingston, Eric Gisin, and * Michael Rendell was ripped from pdksh 5.0.8 and hacked for use with * ash by J.T. Conklin. * * Public domain. */ struct limits { const char *name; const char *unit; char option; int8_t cmd; /* all RLIMIT_xxx are <= 127 */ unsigned short factor; /* multiply by to get rlim_{cur,max} values */ }; #define OPTSTRING_BASE "HSa" static const struct limits limits[] = { #ifdef RLIMIT_CPU { "time", "seconds", 't', RLIMIT_CPU, 1 }, #define OPTSTRING_t OPTSTRING_BASE "t" #else #define OPTSTRING_t OPTSTRING_BASE #endif #ifdef RLIMIT_FSIZE { "file", "blocks", 'f', RLIMIT_FSIZE, 512 }, #define OPTSTRING_f OPTSTRING_t "f" #else #define OPTSTRING_f OPTSTRING_t #endif #ifdef RLIMIT_DATA { "data", "kbytes", 'd', RLIMIT_DATA, 1024 }, #define OPTSTRING_d OPTSTRING_f "d" #else #define OPTSTRING_d OPTSTRING_f #endif #ifdef RLIMIT_STACK { "stack", "kbytes", 's', RLIMIT_STACK, 1024 }, #define OPTSTRING_s OPTSTRING_d "s" #else #define OPTSTRING_s OPTSTRING_d #endif #ifdef RLIMIT_CORE { "coredump", "blocks", 'c', RLIMIT_CORE, 512 }, #define OPTSTRING_c OPTSTRING_s "c" #else #define OPTSTRING_c OPTSTRING_s #endif #ifdef RLIMIT_RSS { "memory", "kbytes", 'm', RLIMIT_RSS, 1024 }, #define OPTSTRING_m OPTSTRING_c "m" #else #define OPTSTRING_m OPTSTRING_c #endif #ifdef RLIMIT_MEMLOCK { "locked memory","kbytes", 'l', RLIMIT_MEMLOCK, 1024 }, #define OPTSTRING_l OPTSTRING_m "l" #else #define OPTSTRING_l OPTSTRING_m #endif #ifdef RLIMIT_NTHR { "thread", "threads", 'r', RLIMIT_NTHR, 1 }, #define OPTSTRING_r OPTSTRING_l "r" #else #define OPTSTRING_r OPTSTRING_l #endif #ifdef RLIMIT_NPROC { "process", "processes", 'p', RLIMIT_NPROC, 1 }, #define OPTSTRING_p OPTSTRING_r "p" #else #define OPTSTRING_p OPTSTRING_r #endif #ifdef RLIMIT_NOFILE { "nofiles", "descriptors", 'n', RLIMIT_NOFILE, 1 }, #define OPTSTRING_n OPTSTRING_p "n" #else #define OPTSTRING_n OPTSTRING_p #endif #ifdef RLIMIT_VMEM { "vmemory", "kbytes", 'v', RLIMIT_VMEM, 1024 }, #define OPTSTRING_v OPTSTRING_n "v" #else #define OPTSTRING_v OPTSTRING_n #endif #ifdef RLIMIT_SWAP { "swap", "kbytes", 'w', RLIMIT_SWAP, 1024 }, #define OPTSTRING_w OPTSTRING_v "w" #else #define OPTSTRING_w OPTSTRING_v #endif #ifdef RLIMIT_SBSIZE { "sbsize", "bytes", 'b', RLIMIT_SBSIZE, 1 }, #define OPTSTRING_b OPTSTRING_w "b" #else #define OPTSTRING_b OPTSTRING_w #endif { NULL, NULL, '\0', 0, 0 } }; #define OPTSTRING OPTSTRING_b int ulimitcmd(int argc, char **argv) { int c; rlim_t val = 0; enum { SOFT = 0x1, HARD = 0x2 } how = 0, which; const struct limits *l; int set, all = 0; int optc, what; struct rlimit limit; what = 'f'; while ((optc = nextopt(OPTSTRING)) != '\0') switch (optc) { case 'H': how |= HARD; break; case 'S': how |= SOFT; break; case 'a': all = 1; break; default: what = optc; } for (l = limits; l->name && l->option != what; l++) ; if (!l->name) error("internal error (%c)", what); set = *argptr ? 1 : 0; if (set) { char *p = *argptr; if (all || argptr[1]) error("too many arguments"); if (how == 0) how = HARD | SOFT; if (strcmp(p, "unlimited") == 0) val = RLIM_INFINITY; else { val = (rlim_t) 0; while ((c = *p++) >= '0' && c <= '9') { if (val >= RLIM_INFINITY/10) error("%s: value overflow", *argptr); val = (val * 10); if (val >= RLIM_INFINITY - (long)(c - '0')) error("%s: value overflow", *argptr); val += (long)(c - '0'); } if (c) error("%s: bad number", *argptr); if (val > RLIM_INFINITY / l->factor) error("%s: value overflow", *argptr); val *= l->factor; } } else if (how == 0) how = SOFT; if (all) { for (l = limits; l->name; l++) { getrlimit(l->cmd, &limit); out1fmt("%-13s (-%c %-11s) ", l->name, l->option, l->unit); which = how; while (which != 0) { if (which & SOFT) { val = limit.rlim_cur; which &= ~SOFT; } else if (which & HARD) { val = limit.rlim_max; which &= ~HARD; } if (val == RLIM_INFINITY) out1fmt("unlimited"); else { val /= l->factor; #ifdef BSD4_4 out1fmt("%9lld", (long long) val); #else out1fmt("%9ld", (long) val); #endif } out1fmt("%c", which ? '\t' : '\n'); } } goto done; } if (getrlimit(l->cmd, &limit) == -1) error("error getting limit (%s)", strerror(errno)); if (set) { if (how & HARD) limit.rlim_max = val; if (how & SOFT) limit.rlim_cur = val; if (setrlimit(l->cmd, &limit) < 0) error("error setting limit (%s)", strerror(errno)); if (l->cmd == RLIMIT_NOFILE) user_fd_limit = sysconf(_SC_OPEN_MAX); } else { if (how & SOFT) val = limit.rlim_cur; else if (how & HARD) val = limit.rlim_max; if (val == RLIM_INFINITY) out1fmt("unlimited\n"); else { val /= l->factor; #ifdef BSD4_4 out1fmt("%lld\n", (long long) val); #else out1fmt("%ld\n", (long) val); #endif } } done:; flushout(out1); if (io_err(out1)) { out2str("ulimit: I/O error (stdout)\n"); return 1; } return 0; } @ 1.53 log @ It appears that POSIX intends to add a -d X option to the read command in its next version, so it can be used as -d '' (to specify a \0 end character for the record read, rather than the default \n) to accompany find -print0 and xargs -0 options (also likely to be added). Add support for -d now. While here fix a bug where escaped nul chars (\ \0) in non-raw mode were not being dropped, as they are when not escaped (if not dropped, they're still not used in any useful way, they just ended the value at that point). @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.52 2022/08/19 12:52:31 kre Exp $ */ d40 1 a40 1 __RCSID("$NetBSD: miscbltin.c,v 1.52 2022/08/19 12:52:31 kre Exp $"); d105 2 d137 1 d204 16 a219 2 STACKSTRNUL(p); setvar(*ap, stackblock(), 0); d237 12 d254 2 @ 1.53.2.1 log @Pull up following revision(s) (requested by kre in ticket #454): bin/sh/miscbltin.c: revision 1.54 If the read builtin is told to read into IFS, we must avoid doing that until all current uses of IFS are complete (as we have IFS's value cached in ifs - if IFS alters, ifs might point anywhere). Handle this by deferring assignments to IFS until everything is done. This makes us appear to comply with the (currently) proposed requirement for read by POSIX that field splitting complete before vars are assigned. (Other shells, like dash, ksh93, yash, bosh behave like this) That might end up being unspecified though, as other shells (bosh, mksh) assign each field to its var as it is delimited (though bosh appears to have bugs). If we wanted to go that route, the issue here could have been handled by re-doing the init of ifs after every setvar() that is performed here (except the last, after which it is no longer needed). @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.53 2022/12/11 08:23:10 kre Exp $ */ d40 1 a40 1 __RCSID("$NetBSD: miscbltin.c,v 1.53 2022/12/11 08:23:10 kre Exp $"); a104 2 char *newifs = NULL; struct stackmark mk; a134 1 setstackmark(&mk); d201 2 a202 16 if (equal(*ap, "IFS")) { /* * we must not alter the value of IFS, as our * local "ifs" var is (perhaps) pointing at it, * at best we would be using data after free() * the next time we reference ifs - but that mem * may have been reused for something different. * * note that this might occur several times */ STPUTC('\0', p); newifs = grabstackstr(p); } else { STACKSTRNUL(p); setvar(*ap, stackblock(), 0); } a219 12 /* * If IFS was one of the variables named, we can finally set it now * (no further references to ifs will be made) */ if (newifs != NULL) setvar("IFS", newifs, 0); /* * Now we can assign to the final variable (which might * also be IFS, hence the ordering here) */ a224 2 popstackmark(&mk); @ 1.52 log @Don't output the error for bad usage (no var name given) after already writing the prompt (set with the -p option). That results in nonsense like: $ read -p foo fooread: arg count While here, improve the error message so it means something. Now we will get: $ read -p foo read: variable name required Usage: read [-r] [-p prompt] var... [Detected by code reading while doing the work for the previous fix] @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.51 2022/08/19 12:17:18 kre Exp $ */ d40 1 a40 1 __RCSID("$NetBSD: miscbltin.c,v 1.51 2022/08/19 12:17:18 kre Exp $"); d94 1 d106 1 d109 6 a114 2 while ((i = nextopt("p:r")) != '\0') { if (i == 'p') d116 2 a117 1 else d119 2 d143 1 a143 3 if (c == '\0') continue; if (c == '\\' && !rflag) { d148 1 a148 1 if (c != '\n') d152 1 a152 1 if (c == '\n') d154 2 d179 2 @ 1.51 log @PR bin/56972 Fix escape ('\') handling in sh read builtin. In 1.35 (March 2005) (the big read fixup), most escape handling and IFS processing in the read builtin was corrected. However 2 cases were missed, one is a word (something to be assigned to any variable but the last) in which every character is escaped (the code was relying on a non-escaped char to set the "in a word" status), and second trailing IFS whitespace at the end of the line was being deleted, even if the chars had been escaped (the escape chars are no longer present). See the PR for more details (including the case that detected the problem). After fixing this, I looked at the FreeBSD code (normally might do it before, but these fixes were trivial) to check their implementation. Their code does similar things to ours now does, but in a completely different way, their read builtin is more complex than ours needs to be (they handle more options). For anyone tempted to simply incorporate their code, note that it relies upon infrastructure changes elsewhere in the shell, so would not be a simple cut and drop in exercise. This needs pullups to -3 -4 -5 -6 -7 -8 and -9 (fortunately this is happening before -10 is branched, so will never be broken this way there). @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.50 2022/04/16 14:26:26 kre Exp $ */ d40 1 a40 1 __RCSID("$NetBSD: miscbltin.c,v 1.50 2022/04/16 14:26:26 kre Exp $"); d114 4 a122 3 if (*(ap = argptr) == NULL) error("arg count"); @ 1.50 log @Redo the way the builtin cmd 'ulimit' getopt() (nextopt() really, but it is essentially the same) arg string is generated, to lessen the chances that the table of limits, and the arg string that allows limits to be reported or set will get out of sync. They weren't (as long as we didn't grow an RLIMIT_SWAP) this is just tidier. While here, reorder the limits table fields, and shrink a couple that were needlessly wasteful, to save some space -- for most architectures this should save 8 bytes per table entry (there are currently 13). (Some minor code bloat offsets this slightly because of int type promotions now required). NFCI. @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.49 2022/04/16 14:23:36 kre Exp $ */ d40 1 a40 1 __RCSID("$NetBSD: miscbltin.c,v 1.49 2022/04/16 14:23:36 kre Exp $"); d103 1 d141 1 a141 1 STPUTC(c, p); d168 1 d175 1 d193 1 d198 1 a198 1 for (; stackblock() <= --p; *p = 0) { @ 1.49 log @While doing the previous change, I noticed that when used in a particularly perverse way, the error message for a bad octal constant as the new umask value could incorrectly claim that the -S option (which would need to be present to cause this issue) was the detected bad value. Fix that to report the actual incorrect arg. And while fiddling, also check for args to umask that are too big to be sane mask values (the biggest permitted is 07777) and use mode_t as the mask variable type, rather than int. @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.48 2022/04/16 14:20:45 kre Exp $ */ d40 1 a40 1 __RCSID("$NetBSD: miscbltin.c,v 1.48 2022/04/16 14:20:45 kre Exp $"); a318 2 int cmd; int factor; /* multiply by to get rlim_{cur,max} values */ d320 2 d324 2 d328 4 a331 1 { "time", "seconds", RLIMIT_CPU, 1, 't' }, d334 4 a337 1 { "file", "blocks", RLIMIT_FSIZE, 512, 'f' }, d340 4 a343 1 { "data", "kbytes", RLIMIT_DATA, 1024, 'd' }, d346 4 a349 1 { "stack", "kbytes", RLIMIT_STACK, 1024, 's' }, d352 4 a355 1 { "coredump", "blocks", RLIMIT_CORE, 512, 'c' }, d358 4 a361 1 { "memory", "kbytes", RLIMIT_RSS, 1024, 'm' }, d364 4 a367 1 { "locked memory","kbytes", RLIMIT_MEMLOCK, 1024, 'l' }, d370 4 a373 1 { "thread", "threads", RLIMIT_NTHR, 1, 'r' }, d376 4 a379 1 { "process", "processes", RLIMIT_NPROC, 1, 'p' }, d382 4 a385 1 { "nofiles", "descriptors", RLIMIT_NOFILE, 1, 'n' }, d388 4 a391 1 { "vmemory", "kbytes", RLIMIT_VMEM, 1024, 'v' }, d394 4 a397 1 { "swap", "kbytes", RLIMIT_SWAP, 1024, 'w' }, d400 4 a403 1 { "sbsize", "bytes", RLIMIT_SBSIZE, 1, 'b' }, d405 1 a405 1 { NULL, NULL, 0, 0, '\0' } d407 1 d422 1 a422 1 while ((optc = nextopt("HSabtfdscmlrpnv")) != '\0') d458 1 a458 1 error("value overflow"); d461 1 a461 1 error("value overflow"); d465 1 a465 1 error("bad number"); d467 1 a467 1 error("value overflow"); @ 1.48 log @Avoid generating error messages implying that user errors are illegal. @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.47 2021/12/12 11:18:46 andvar Exp $ */ d40 1 a40 1 __RCSID("$NetBSD: miscbltin.c,v 1.47 2021/12/12 11:18:46 andvar Exp $"); d218 1 a218 1 int mask; d268 2 d274 1 a274 1 argv[1]); d276 2 d279 2 @ 1.47 log @s/Miscelaneous/Miscellaneous/ and s/slahes/slashes/ in comments. @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.46 2021/11/16 11:27:50 kre Exp $ */ d40 1 a40 1 __RCSID("$NetBSD: miscbltin.c,v 1.46 2021/11/16 11:27:50 kre Exp $"); d271 2 a272 1 error("Illegal number: %s", argv[1]); @ 1.46 log @Detect write errors to stdout, and exit(1) from some built-in commands which (primarily) are used just to generate output (or with a particular option combination do so). @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.45 2021/09/15 18:30:57 kre Exp $ */ d40 1 a40 1 __RCSID("$NetBSD: miscbltin.c,v 1.45 2021/09/15 18:30:57 kre Exp $"); d45 1 a45 1 * Miscelaneous builtins. d74 1 a74 1 * Backslahes escape the next char unless -r is specified. @ 1.45 log @Have the ulimit command watch for ulimit -n (alter number of available fds) and keep the rest of the shell aware of any changes. While here, modify 'ulimit -aSH' to print both the soft and hard limits for the resources, rather than just (in this case, as H comes last) the hard limit. In any other case when both S and H are present, and we're examining a limit, use the soft limit (just as if neither were given). No change for setting limits (both are set, unless exactly one of -H or -S is given). However, we now check for overflow when converting the value to be assigned, rather than just truncating the value however it happens to work out... @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.44 2017/05/13 15:03:34 gson Exp $ */ d40 1 a40 1 __RCSID("$NetBSD: miscbltin.c,v 1.44 2017/05/13 15:03:34 gson Exp $"); d291 5 d453 1 a453 1 return 0; d485 6 @ 1.44 log @Fix inconsistent whitespace @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.43 2015/05/09 13:28:55 christos Exp $ */ d40 1 a40 1 __RCSID("$NetBSD: miscbltin.c,v 1.43 2015/05/09 13:28:55 christos Exp $"); d66 1 d361 1 a361 1 how = SOFT | HARD; d371 1 a371 1 how = HARD; d374 1 a374 1 how = SOFT; d394 3 d402 8 a409 2 while ((c = *p++) >= '0' && c <= '9') val = (val * 10) + (long)(c - '0'); d412 2 d416 3 a418 1 } d422 2 a423 4 if (how & SOFT) val = limit.rlim_cur; else if (how & HARD) val = limit.rlim_max; d425 14 a438 7 out1fmt("%-13s (-%c %-11s) ", l->name, l->option, l->unit); if (val == RLIM_INFINITY) out1fmt("unlimited\n"); else { val /= l->factor; d440 1 a440 1 out1fmt("%lld\n", (long long) val); d442 1 a442 1 out1fmt("%ld\n", (long) val); d444 2 d460 2 @ 1.44.2.1 log @Pull up following revision(s) (requested by kre in ticket #1779): bin/sh/miscbltin.c: revision 1.51 bin/sh/miscbltin.c: revision 1.52 PR bin/56972 Fix escape ('\') handling in sh read builtin. In 1.35 (March 2005) (the big read fixup), most escape handling and IFS processing in the read builtin was corrected. However 2 cases were missed, one is a word (something to be assigned to any variable but the last) in which every character is escaped (the code was relying on a non-escaped char to set the "in a word" status), and second trailing IFS whitespace at the end of the line was being deleted, even if the chars had been escaped (the escape chars are no longer present). See the PR for more details (including the case that detected the problem). After fixing this, I looked at the FreeBSD code (normally might do it before, but these fixes were trivial) to check their implementation. Their code does similar things to ours now does, but in a completely different way, their read builtin is more complex than ours needs to be (they handle more options). For anyone tempted to simply incorporate their code, note that it relies upon infrastructure changes elsewhere in the shell, so would not be a simple cut and drop in exercise. This needs pullups to -3 -4 -5 -6 -7 -8 and -9 (fortunately this is happening before -10 is branched, so will never be broken this way there). - Don't output the error for bad usage (no var name given) after already writing the prompt (set with the -p option). That results in nonsense like: $ read -p foo fooread: arg count While here, improve the error message so it means something. Now we will get: $ read -p foo read: variable name required Usage: read [-r] [-p prompt] var... [Detected by code reading while doing the work for the previous fix] @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.44 2017/05/13 15:03:34 gson Exp $ */ d40 1 a40 1 __RCSID("$NetBSD: miscbltin.c,v 1.44 2017/05/13 15:03:34 gson Exp $"); a101 1 ptrdiff_t wordlen = 0; a111 4 if (*(ap = argptr) == NULL) error("variable name required\n" "Usage: read [-r] [-p prompt] var..."); d117 3 d139 1 a139 1 goto wdch; a165 1 wdch:; a171 1 wordlen = p - stackblock(); a188 1 wordlen = 0; d193 1 a193 1 for (; stackblock() + wordlen <= --p; *p = 0) { @ 1.44.12.1 log @Pull up following revision(s) (requested by kre in ticket #1549): bin/sh/miscbltin.c: revision 1.51 bin/sh/miscbltin.c: revision 1.52 PR bin/56972 Fix escape ('\') handling in sh read builtin. In 1.35 (March 2005) (the big read fixup), most escape handling and IFS processing in the read builtin was corrected. However 2 cases were missed, one is a word (something to be assigned to any variable but the last) in which every character is escaped (the code was relying on a non-escaped char to set the "in a word" status), and second trailing IFS whitespace at the end of the line was being deleted, even if the chars had been escaped (the escape chars are no longer present). See the PR for more details (including the case that detected the problem). After fixing this, I looked at the FreeBSD code (normally might do it before, but these fixes were trivial) to check their implementation. Their code does similar things to ours now does, but in a completely different way, their read builtin is more complex than ours needs to be (they handle more options). For anyone tempted to simply incorporate their code, note that it relies upon infrastructure changes elsewhere in the shell, so would not be a simple cut and drop in exercise. This needs pullups to -3 -4 -5 -6 -7 -8 and -9 (fortunately this is happening before -10 is branched, so will never be broken this way there). - Don't output the error for bad usage (no var name given) after already writing the prompt (set with the -p option). That results in nonsense like: $ read -p foo fooread: arg count While here, improve the error message so it means something. Now we will get: $ read -p foo read: variable name required Usage: read [-r] [-p prompt] var... [Detected by code reading while doing the work for the previous fix] @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.44 2017/05/13 15:03:34 gson Exp $ */ d40 1 a40 1 __RCSID("$NetBSD: miscbltin.c,v 1.44 2017/05/13 15:03:34 gson Exp $"); a101 1 ptrdiff_t wordlen = 0; a111 4 if (*(ap = argptr) == NULL) error("variable name required\n" "Usage: read [-r] [-p prompt] var..."); d117 3 d139 1 a139 1 goto wdch; a165 1 wdch:; a171 1 wordlen = p - stackblock(); a188 1 wordlen = 0; d193 1 a193 1 for (; stackblock() + wordlen <= --p; *p = 0) { @ 1.44.10.1 log @Sync with HEAD @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.44 2017/05/13 15:03:34 gson Exp $ */ d40 1 a40 1 __RCSID("$NetBSD: miscbltin.c,v 1.44 2017/05/13 15:03:34 gson Exp $"); @ 1.44.10.2 log @Ooops, restore accidently removed files from merge mishap @ text @@ 1.43 log @CID 1225078: check getrlimit return @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.42 2012/06/11 18:28:10 njoly Exp $ */ d40 1 a40 1 __RCSID("$NetBSD: miscbltin.c,v 1.42 2012/06/11 18:28:10 njoly Exp $"); d324 1 a324 1 #ifdef RLIMIT_CORE @ 1.43.6.1 log @Resolve conflicts from previous merge (all resulting from $NetBSD keywork expansion) @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.44 2017/05/13 15:03:34 gson Exp $ */ d40 1 a40 1 __RCSID("$NetBSD: miscbltin.c,v 1.44 2017/05/13 15:03:34 gson Exp $"); d324 1 a324 1 #ifdef RLIMIT_CORE @ 1.42 log @Allow thread limit queries by adding the new -r flag to ulimit. Add the corresponding documentation in the man page. @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.41 2012/06/09 02:49:48 christos Exp $ */ d40 1 a40 1 __RCSID("$NetBSD: miscbltin.c,v 1.41 2012/06/09 02:49:48 christos Exp $"); d430 2 a431 1 getrlimit(l->cmd, &limit); @ 1.41 log @support RLIMIT_NTHR. @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.40 2011/10/11 15:27:11 christos Exp $ */ d40 1 a40 1 __RCSID("$NetBSD: miscbltin.c,v 1.40 2011/10/11 15:27:11 christos Exp $"); d367 1 a367 1 while ((optc = nextopt("HSabtfdsmcnplv")) != '\0') @ 1.40 log @print the flag too next to the units like bash does. @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.39 2011/06/18 21:18:46 christos Exp $ */ d40 1 a40 1 __RCSID("$NetBSD: miscbltin.c,v 1.39 2011/06/18 21:18:46 christos Exp $"); d333 3 @ 1.40.2.1 log @sync with head @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.40 2011/10/11 15:27:11 christos Exp $ */ d40 1 a40 1 __RCSID("$NetBSD: miscbltin.c,v 1.40 2011/10/11 15:27:11 christos Exp $"); a332 3 #ifdef RLIMIT_NTHR { "thread", "threads", RLIMIT_NTHR, 1, 'r' }, #endif d364 1 a364 1 while ((optc = nextopt("HSabtfdscmlrpnv")) != '\0') @ 1.39 log @PR/45069: Henning Petersen: Use prototypes from builtins.h . @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.38 2009/03/29 01:02:49 mrg Exp $ */ d40 1 a40 1 __RCSID("$NetBSD: miscbltin.c,v 1.38 2009/03/29 01:02:49 mrg Exp $"); d305 1 d313 1 a313 1 { "time(seconds)", RLIMIT_CPU, 1, 't' }, d316 1 a316 1 { "file(blocks)", RLIMIT_FSIZE, 512, 'f' }, d319 1 a319 1 { "data(kbytes)", RLIMIT_DATA, 1024, 'd' }, d322 1 a322 1 { "stack(kbytes)", RLIMIT_STACK, 1024, 's' }, d325 1 a325 1 { "coredump(blocks)", RLIMIT_CORE, 512, 'c' }, d328 1 a328 1 { "memory(kbytes)", RLIMIT_RSS, 1024, 'm' }, d331 1 a331 1 { "locked memory(kbytes)", RLIMIT_MEMLOCK, 1024, 'l' }, d334 1 a334 1 { "process(processes)", RLIMIT_NPROC, 1, 'p' }, d337 1 a337 1 { "nofiles(descriptors)", RLIMIT_NOFILE, 1, 'n' }, d340 1 a340 1 { "vmemory(kbytes)", RLIMIT_VMEM, 1024, 'v' }, d343 1 a343 1 { "swap(kbytes)", RLIMIT_SWAP, 1024, 'w' }, d346 1 a346 1 { "sbsize(bytes)", RLIMIT_SBSIZE, 1, 'b' }, d348 1 a348 1 { (char *) 0, 0, 0, '\0' } d410 2 a411 1 out1fmt("%-20s ", l->name); @ 1.38 log @- add new RLIMIT_AS (aka RLIMIT_VMEM) resource that limits the total address space available to processes. this limit exists in most other modern unix variants, and like most of them, our defaults are unlimited. remove the old mmap / rlimit.datasize hack. - adds the VMCMD_STACK flag to all the stack-creation vmcmd callers. it is currently unused, but was added a few years ago. - add a pair of new process size values to kinfo_proc2{}. one is the total size of the process memory map, and the other is the total size adjusted for unused stack space (since most processes have a lot of this...) - patch sh, and csh to notice RLIMIT_AS. (in some cases, the alias RLIMIT_VMEM was already present and used if availble.) - patch ps, top and systat to notice the new k_vm_vsize member of kinfo_proc2{}. - update irix, svr4, svr4_32, linux and osf1 emulations to support this information. (freebsd could be done, but that it's best left as part of the full-update of compat/freebsd.) this addresses PR 7897. it also gives correct memory usage values, which have never been entirely correct (since mmap), and have been very incorrect since jemalloc() was enabled. tested on i386 and sparc64, build tested on several other platforms. thanks to many folks for feedback and testing but most espcially chuq and yamt for critical suggestions that lead to this patch not having a special ugliness i wasn't happy with anyway :-) @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.37 2008/12/28 19:53:37 christos Exp $ */ d40 1 a40 1 __RCSID("$NetBSD: miscbltin.c,v 1.37 2008/12/28 19:53:37 christos Exp $"); d64 1 a64 1 #include "miscbltin.h" @ 1.38.4.1 log @Catchup with rmind-uvmplock merge. @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.39 2011/06/18 21:18:46 christos Exp $ */ d40 1 a40 1 __RCSID("$NetBSD: miscbltin.c,v 1.39 2011/06/18 21:18:46 christos Exp $"); d64 1 a64 1 #include "builtins.h" @ 1.37 log @rlim_t will be unsigned as TOG mandates. @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.36 2005/10/01 20:23:54 christos Exp $ */ d40 1 a40 1 __RCSID("$NetBSD: miscbltin.c,v 1.36 2005/10/01 20:23:54 christos Exp $"); d363 1 a363 1 while ((optc = nextopt("HSabtfdsmcnpl")) != '\0') @ 1.37.2.1 log @Sync with HEAD. Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.38 2009/03/29 01:02:49 mrg Exp $ */ d40 1 a40 1 __RCSID("$NetBSD: miscbltin.c,v 1.38 2009/03/29 01:02:49 mrg Exp $"); d363 1 a363 1 while ((optc = nextopt("HSabtfdsmcnplv")) != '\0') @ 1.36 log @fix setmode error handling. @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.35 2005/03/19 14:22:50 dsl Exp $ */ d40 1 a40 1 __RCSID("$NetBSD: miscbltin.c,v 1.35 2005/03/19 14:22:50 dsl Exp $"); a394 1 { a395 3 if (val < (rlim_t) 0) break; } @ 1.36.26.1 log @Pull up following revision(s) (requested by mrg in ticket #622): bin/csh/csh.1: revision 1.46 bin/csh/func.c: revision 1.37 bin/ps/print.c: revision 1.111 bin/ps/ps.c: revision 1.74 bin/sh/miscbltin.c: revision 1.38 bin/sh/sh.1: revision 1.92 via patch external/bsd/top/dist/machine/m_netbsd.c: revision 1.7 lib/libkvm/kvm_proc.c: revision 1.82 sys/arch/mips/mips/cpu_exec.c: revision 1.55 sys/compat/darwin/darwin_exec.c: revision 1.57 sys/compat/ibcs2/ibcs2_exec.c: revision 1.73 sys/compat/irix/irix_resource.c: revision 1.15 sys/compat/linux/arch/amd64/linux_exec_machdep.c: revision 1.16 sys/compat/linux/arch/i386/linux_exec_machdep.c: revision 1.12 sys/compat/linux/common/linux_limit.h: revision 1.5 sys/compat/osf1/osf1_resource.c: revision 1.14 sys/compat/svr4/svr4_resource.c: revision 1.18 sys/compat/svr4_32/svr4_32_resource.c: revision 1.17 sys/kern/exec_subr.c: revision 1.62 sys/kern/init_sysctl.c: revision 1.160 sys/kern/kern_exec.c: revision 1.288 sys/kern/kern_resource.c: revision 1.151 sys/sys/param.h: patch sys/sys/resource.h: revision 1.31 sys/sys/sysctl.h: revision 1.184 sys/uvm/uvm_extern.h: revision 1.153 sys/uvm/uvm_glue.c: revision 1.136 sys/uvm/uvm_mmap.c: revision 1.128 usr.bin/systat/ps.c: revision 1.32 - - add new RLIMIT_AS (aka RLIMIT_VMEM) resource that limits the total address space available to processes. this limit exists in most other modern unix variants, and like most of them, our defaults are unlimited. remove the old mmap / rlimit.datasize hack. - - adds the VMCMD_STACK flag to all the stack-creation vmcmd callers. it is currently unused, but was added a few years ago. - - add a pair of new process size values to kinfo_proc2{}. one is the total size of the process memory map, and the other is the total size adjusted for unused stack space (since most processes have a lot of this...) - - patch sh, and csh to notice RLIMIT_AS. (in some cases, the alias RLIMIT_VMEM was already present and used if availble.) - - patch ps, top and systat to notice the new k_vm_vsize member of kinfo_proc2{}. - - update irix, svr4, svr4_32, linux and osf1 emulations to support this information. (freebsd could be done, but that it's best left as part of the full-update of compat/freebsd.) this addresses PR 7897. it also gives correct memory usage values, which have never been entirely correct (since mmap), and have been very incorrect since jemalloc() was enabled. tested on i386 and sparc64, build tested on several other platforms. thanks to many folks for feedback and testing but most espcially chuq and yamt for critical suggestions that lead to this patch not having a special ugliness i wasn't happy with anyway :-) @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.36 2005/10/01 20:23:54 christos Exp $ */ d40 1 a40 1 __RCSID("$NetBSD: miscbltin.c,v 1.36 2005/10/01 20:23:54 christos Exp $"); d363 1 a363 1 while ((optc = nextopt("HSabtfdsmcnplv")) != '\0') @ 1.35 log @Fix the way the 'read' builtin processes IFS. In particular: - IFS whitespace is now processes correctly, - Trailing non-whitespace IFS characters are added to the last variable iff a subsequent variable would have been assigned a non-null string. Now passes the 'read' tests in http://www.research.att.com/~gsf/public/ifs.sh @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.34 2004/04/19 01:36:32 lukem Exp $ */ d40 1 a40 1 __RCSID("$NetBSD: miscbltin.c,v 1.34 2004/04/19 01:36:32 lukem Exp $"); d284 2 a285 1 error("Illegal mode: %s", ap); @ 1.34 log @Correct the description of sbsize; it is parsed in bytes not kbytes. @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.33 2004/04/17 15:41:29 christos Exp $ */ d40 1 a40 1 __RCSID("$NetBSD: miscbltin.c,v 1.33 2004/04/17 15:41:29 christos Exp $"); d72 2 a73 2 * The read builtin. The -e option causes backslashes to escape the * following character. d76 10 a91 1 int backslash; d95 1 a95 1 char *ifs; d100 2 d111 1 d116 1 d119 1 d121 2 a122 1 ifs = nullstr; d124 1 a124 2 startword = 1; backslash = 0; d133 5 a137 2 if (backslash) { backslash = 0; a141 4 if (!rflag && c == '\\') { backslash++; continue; } d144 28 a171 1 if (startword && *ifs == ' ' && strchr(ifs, c)) { d174 7 a180 14 startword = 0; if (backslash && c == '\\') { if (read(0, &c, 1) != 1) { status = 1; break; } STPUTC(c, p); } else if (ap[1] != NULL && strchr(ifs, c) != NULL) { STACKSTRNUL(p); setvar(*ap, stackblock(), 0); ap++; startword = 1; STARTSTACKSTR(p); } else { d182 1 d184 5 d191 12 a202 3 /* Remove trailing blanks */ while (stackblock() <= --p && strchr(ifs, *p) != NULL) *p = '\0'; d204 2 @ 1.34.2.1 log @Pull up revision 1.35 (requested by dsl in ticket #117): Fix the way the 'read' builtin processes IFS. In particular: - IFS whitespace is now processes correctly, - Trailing non-whitespace IFS characters are added to the last variable iff a subsequent variable would have been assigned a non-null string. Now passes the 'read' tests in http://www.research.att.com/~gsf/public/ifs.sh @ text @d1 1 a1 1 /* $NetBSD$ */ d40 1 a40 1 __RCSID("$NetBSD$"); d72 2 a73 2 * The read builtin. * Backslahes escape the next char unless -r is specified. a75 10 * * Note that if IFS=' :' then read x y should work so that: * 'a b' x='a', y='b' * ' a b ' x='a', y='b' * ':b' x='', y='b' * ':' x='', y='' * '::' x='', y='' * ': :' x='', y='' * ':::' x='', y='::' * ':b c:' x='', y='b c:' d82 1 d86 1 a86 1 const char *ifs; a90 2 int is_ifs; int saveall = 0; a99 1 a103 1 a105 1 d107 1 a107 2 ifs = " \t\n"; d109 2 a110 1 startword = 2; d119 2 a120 5 if (c == '\\' && !rflag) { if (read(0, &c, 1) != 1) { status = 1; break; } d125 4 d131 8 a138 18 if (strchr(ifs, c)) is_ifs = strchr(" \t\n", c) ? 1 : 2; else is_ifs = 0; if (startword != 0) { if (is_ifs == 1) { /* Ignore leading IFS whitespace */ if (saveall) STPUTC(c, p); continue; } if (is_ifs == 2 && startword == 1) { /* Only one non-whitespace IFS per word */ startword = 2; if (saveall) STPUTC(c, p); continue; a139 8 } if (is_ifs == 0) { /* append this character to the current variable */ startword = 0; if (saveall) /* Not just a spare terminator */ saveall++; d141 7 a147 9 continue; } /* end of variable... */ startword = is_ifs; if (ap[1] == NULL) { /* Last variable needs all IFS chars */ saveall++; a148 1 continue; a149 5 STACKSTRNUL(p); setvar(*ap, stackblock(), 0); ap++; STARTSTACKSTR(p); d152 3 a154 12 /* Remove trailing IFS chars */ for (; stackblock() <= --p; *p = 0) { if (!strchr(ifs, *p)) break; if (strchr(" \t\n", *p)) /* Always remove whitespace */ continue; if (saveall > 1) /* Don't remove non-whitespace unless it was naked */ break; } a155 2 /* Set any remaining args to "" */ @ 1.33 log @understand rlimit sbsize @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.32 2003/08/07 09:05:35 agc Exp $ */ d40 1 a40 1 __RCSID("$NetBSD: miscbltin.c,v 1.32 2003/08/07 09:05:35 agc Exp $"); d294 1 a294 1 { "sbsize(kbytes)", RLIMIT_SBSIZE, 1, 'b' }, @ 1.32 log @Move UCB-licensed code from 4-clause to 3-clause licence. Patches provided by Joel Baker in PR 22249, verified by myself. @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.31 2002/11/24 22:35:41 christos Exp $ */ d40 1 a40 1 __RCSID("$NetBSD: miscbltin.c,v 1.31 2002/11/24 22:35:41 christos Exp $"); d293 3 d312 1 a312 1 while ((optc = nextopt("HSatfdsmcnpl")) != '\0') @ 1.31 log @Fixes from David Laight: - ansification - format of output of jobs command (etc) - job identiers %+, %- etc - $? and $(...) - correct quoting of output of set, export -p and readonly -p - differentiation between nornal and 'posix special' builtins - correct behaviour (posix) for errors on builtins and special builtins - builtin printf and kill - set -o debug (if compiled with DEBUG) - cd src obj (as ksh - too useful to do without) - unset -e name, remove non-readonly variable from export list. (so I could unset -e PS1 before running the test shell...) @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.30 2001/02/04 19:52:06 christos Exp $ */ d18 1 a18 5 * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors d40 1 a40 1 __RCSID("$NetBSD: miscbltin.c,v 1.30 2001/02/04 19:52:06 christos Exp $"); @ 1.30 log @remove redundant declarations and nexted externs. @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.29 2001/01/04 15:39:51 lukem Exp $ */ d44 1 a44 1 __RCSID("$NetBSD: miscbltin.c,v 1.29 2001/01/04 15:39:51 lukem Exp $"); d83 1 a83 3 readcmd(argc, argv) int argc; char **argv; d168 1 a168 3 umaskcmd(argc, argv) int argc; char **argv; d301 1 a301 3 ulimitcmd(argc, argv) int argc; char **argv; @ 1.29 log @use more standard %ll_ in favour of %q_ @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.28 2000/11/22 19:20:31 christos Exp $ */ d44 1 a44 1 __RCSID("$NetBSD: miscbltin.c,v 1.28 2000/11/22 19:20:31 christos Exp $"); a72 1 extern char **argptr; /* argument list for builtin command */ d102 1 a102 1 prompt = optarg; @ 1.28 log @error message cleanup: - don't print the builtin name twice - explain why things fail - no extra newline @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.27 1998/09/26 19:28:12 christos Exp $ */ d44 1 a44 1 __RCSID("$NetBSD: miscbltin.c,v 1.27 1998/09/26 19:28:12 christos Exp $"); d377 1 a377 1 out1fmt("%qd\n", (long long) val); d406 1 a406 1 out1fmt("%qd\n", (long long) val); @ 1.27 log @include to get the prototype for free() @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.26 1998/09/24 17:49:48 itohy Exp $ */ d44 1 a44 1 __RCSID("$NetBSD: miscbltin.c,v 1.26 1998/09/24 17:49:48 itohy Exp $"); d60 1 d338 1 a338 1 error("ulimit: internal error (%c)\n", what); d345 1 a345 1 error("ulimit: too many arguments\n"); d358 1 a358 1 error("ulimit: bad number\n"); d388 2 a391 2 if (how & HARD) limit.rlim_max = val; d393 1 a393 1 error("ulimit: bad limit\n"); @ 1.26 log @The return value of setmode(3) is a pointer to malloc()'ed area and must be freed to avoid memory leaks if called repeatedly. The leaks occured on symbolic umask command, such as "umask go-w", which is undocumented. @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.25 1998/05/20 00:32:05 christos Exp $ */ d44 1 a44 1 __RCSID("$NetBSD: miscbltin.c,v 1.25 1998/05/20 00:32:05 christos Exp $"); d58 1 @ 1.25 log @Cast is*() args to unsigned chars in case the ctype macros are implemented using arrays. @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.24 1998/02/04 20:10:17 thorpej Exp $ */ d44 1 a44 1 __RCSID("$NetBSD: miscbltin.c,v 1.24 1998/02/04 20:10:17 thorpej Exp $"); a232 2 if ((set = setmode (ap)) == 0) error("Illegal number: %s", ap); d234 9 a242 1 mask = getmode (set, ~mask & 0777); @ 1.24 log @Fix printf formats so they work on the Alpha. @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.23 1998/01/21 10:47:39 christos Exp $ */ d44 1 a44 1 __RCSID("$NetBSD: miscbltin.c,v 1.23 1998/01/21 10:47:39 christos Exp $"); d223 1 a223 1 if (isdigit(*ap)) { @ 1.23 log @BSD4_4 is a standard symbol in ; make sure that files that need this defined, include and don't define it in the Makefile. Add a comment to that effect. @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.22 1998/01/16 16:26:22 christos Exp $ */ d44 1 a44 1 __RCSID("$NetBSD: miscbltin.c,v 1.22 1998/01/16 16:26:22 christos Exp $"); d369 1 a369 1 out1fmt("%qd\n", (quad_t) val); d398 1 a398 1 out1fmt("%qd\n", (quad_t) val); @ 1.22 log @test for the boundary condition in the previous trailing blank fix @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.21 1998/01/15 19:39:11 christos Exp $ */ d44 1 a44 1 __RCSID("$NetBSD: miscbltin.c,v 1.21 1998/01/15 19:39:11 christos Exp $"); d52 2 a53 2 #include #include @ 1.21 log @PR/4805: Ty Sarna: read builtin does not remove trailing blanks. @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.20 1997/11/05 14:05:28 kleink Exp $ */ d44 1 a44 1 __RCSID("$NetBSD: miscbltin.c,v 1.20 1997/11/05 14:05:28 kleink Exp $"); d158 1 a158 1 while (strchr(ifs, *--p) != NULL) @ 1.20 log @Per 1003.2, the (builtin) read utility shall treat the backslash as an escape character (including line continuation), unless the `-r' option is specified: * adopt to this behaviour, add the `-r' option to disable it; * remove the `-e' option, which was previously necessary to get this behaviour. @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.19 1997/07/04 21:02:09 christos Exp $ */ d44 1 a44 1 __RCSID("$NetBSD: miscbltin.c,v 1.19 1997/07/04 21:02:09 christos Exp $"); d157 3 @ 1.19 log @Fix compiler warnings. @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.18 1997/04/11 23:08:15 christos Exp $ */ d44 1 a44 1 __RCSID("$NetBSD$"); d69 1 a69 1 #undef eflag d89 1 a89 1 int eflag; d97 1 a97 1 eflag = 0; d99 1 a99 1 while ((i = nextopt("ep:")) != '\0') { d103 1 a103 1 eflag = 1; d130 1 a130 1 if (eflag && c == '\\') { @ 1.19.2.1 log @Pull rev 1.20 up from trunk (kleink) @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.20 1997/11/05 14:05:28 kleink Exp $ */ d44 1 a44 1 __RCSID("$NetBSD: miscbltin.c,v 1.20 1997/11/05 14:05:28 kleink Exp $"); d69 1 a69 1 #undef rflag d89 1 a89 1 int rflag; d97 1 a97 1 rflag = 0; d99 1 a99 1 while ((i = nextopt("p:r")) != '\0') { d103 1 a103 1 rflag = 1; d130 1 a130 1 if (!rflag && c == '\\') { @ 1.19.2.2 log @Sync with trunk, per request of christos. @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.19.2.1 1997/11/06 07:00:17 mellon Exp $ */ d44 1 a44 1 __RCSID("$NetBSD: miscbltin.c,v 1.19.2.1 1997/11/06 07:00:17 mellon Exp $"); d52 2 a53 2 #include /* quad_t */ #include /* BSD4_4 */ a156 3 /* Remove trailing blanks */ while (stackblock() <= --p && strchr(ifs, *p) != NULL) *p = '\0'; d366 1 a366 1 out1fmt("%qd\n", (long long) val); d395 1 a395 1 out1fmt("%qd\n", (long long) val); @ 1.18 log @Make this work on systems that don't have quads @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.17 1997/01/11 02:04:38 tls Exp $ */ d39 1 d44 1 a44 1 static char rcsid[] = "$NetBSD: miscbltin.c,v 1.17 1997/01/11 02:04:38 tls Exp $"; d66 1 d300 1 a300 1 rlim_t val; @ 1.17 log @kill 'register' @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.16 1996/10/16 15:45:11 christos Exp $ */ d43 1 a43 1 static char rcsid[] = "$NetBSD: miscbltin.c,v 1.16 1996/10/16 15:45:11 christos Exp $"; d52 1 d363 1 d365 3 d392 1 d394 3 @ 1.16 log @PR/2808: Remove trailing whitespace (from FreeBSD) @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.15 1995/06/12 19:44:16 jtc Exp $ */ d43 1 a43 1 static char rcsid[] = "$NetBSD: miscbltin.c,v 1.15 1995/06/12 19:44:16 jtc Exp $"; d296 1 a296 1 register int c; @ 1.15 log @Changed type of rlimit values from quad_t to rlim_t. Cast rlim_t's to quad_t's and use "%qd" in printf. Eliminated unneccessary conditional. @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.14 1995/05/11 21:29:32 christos Exp $ */ d43 1 a43 1 static char rcsid[] = "$NetBSD: miscbltin.c,v 1.14 1995/05/11 21:29:32 christos Exp $"; d81 1 a81 1 char **argv; d165 1 a165 1 char **argv; d226 1 a226 1 void *set; @ 1.15.6.1 log @Update /bin/sh from trunk per request of Christos Zoulas. Fixes many bugs. @ text @d1 1 a1 1 /* $NetBSD: miscbltin.c,v 1.17 1997/01/11 02:04:38 tls Exp $ */ d43 1 a43 1 static char rcsid[] = "$NetBSD: miscbltin.c,v 1.17 1997/01/11 02:04:38 tls Exp $"; d81 1 a81 1 char **argv; d165 1 a165 1 char **argv; d226 1 a226 1 void *set; d296 1 a296 1 int c; @ 1.14 log @Merge in my changes from vangogh, and fix the x=`false`; echo $? == 0 bug. @ text @d1 1 a1 1 /* $NetBSD$ */ d43 1 a43 1 static char rcsid[] = "$NetBSD$"; d297 1 a297 1 quad_t val; d335 1 a335 1 val = (quad_t) 0; d340 1 a340 1 if (val < (quad_t) 0) d362 1 a362 1 out1fmt("%ld\n", (long) val); a380 1 } a381 1 if (!set) { d387 1 a387 1 out1fmt("%ld\n", (long) val); @ 1.13 log @convert to new RCS id conventions. @ text @d41 1 a41 1 static char sccsid[] = "@@(#)miscbltin.c 8.2 (Berkeley) 4/16/94"; d53 2 d57 1 d232 158 @ 1.12 log @clean up further. more patches from Jim Jegers @ text @d1 2 d40 5 a44 2 /*static char sccsid[] = "from: @@(#)miscbltin.c 8.2 (Berkeley) 4/16/94";*/ static char *rcsid = "$Id: miscbltin.c,v 1.11 1994/06/11 16:12:11 mycroft Exp $"; @ 1.11 log @Add RCS ids. @ text @d39 1 a39 1 static char *rcsid = "$Id: $"; d70 5 a74 1 readcmd(argc, argv) char **argv; { d154 5 a158 1 umaskcmd(argc, argv) char **argv; { @ 1.10 log @use prototypes provided by header files instead of our own @ text @d38 2 a39 1 static char sccsid[] = "@@(#)miscbltin.c 8.2 (Berkeley) 4/16/94"; @ 1.9 log @Include appropriate header files to bring function prototypes into scope. @ text @a149 2 extern void *setmode(); extern mode_t getmode(); @ 1.8 log @integrate NetBSD's POSIX.2 compliant umask builtin @ text @d47 2 @ 1.7 log @sync with 4.4lite @ text @d45 2 d148 3 a151 1 char *p; d153 5 d159 40 a198 6 if ((p = argv[1]) == NULL) { INTOFF; mask = umask(0); umask(mask); INTON; out1fmt("%.4o\n", mask); /* %#o might be better */ d200 16 a215 7 mask = 0; do { if ((unsigned)(i = *p - '0') >= 8) error("Illegal number: %s", argv[1]); mask = (mask << 3) + i; } while (*++p != '\0'); umask(mask); @ 1.6 log @do right right thing if 'read' given no args. ptd out by Geoff Rehmet @ text @d2 2 a3 2 * Copyright (c) 1991 The Regents of the University of California. * All rights reserved. d38 1 a38 2 /*static char sccsid[] = "from: @@(#)miscbltin.c 5.2 (Berkeley) 3/13/91";*/ static char rcsid[] = "$Id: miscbltin.c,v 1.5 1993/08/01 18:57:56 mycroft Exp $"; a44 2 #include #include a145 3 extern void *setmode(); extern mode_t getmode(); char *ap; d147 1 a148 5 int symbolic_mode = 0; while ((i = nextopt("S")) != '\0') { symbolic_mode = 1; } d150 6 a155 40 INTOFF; mask = umask(0); umask(mask); INTON; if ((ap = *argptr) == NULL) { if (symbolic_mode) { char u[4], g[4], o[4]; i = 0; if ((mask & S_IRUSR) == 0) u[i++] = 'r'; if ((mask & S_IWUSR) == 0) u[i++] = 'w'; if ((mask & S_IXUSR) == 0) u[i++] = 'x'; u[i] = '\0'; i = 0; if ((mask & S_IRGRP) == 0) g[i++] = 'r'; if ((mask & S_IWGRP) == 0) g[i++] = 'w'; if ((mask & S_IXGRP) == 0) g[i++] = 'x'; g[i] = '\0'; i = 0; if ((mask & S_IROTH) == 0) o[i++] = 'r'; if ((mask & S_IWOTH) == 0) o[i++] = 'w'; if ((mask & S_IXOTH) == 0) o[i++] = 'x'; o[i] = '\0'; out1fmt("u=%s,g=%s,o=%s\n", u, g, o); } else { out1fmt("%.4o\n", mask); } d157 7 a163 16 if (isdigit(*ap)) { mask = 0; do { if (*ap >= '8' || *ap < '0') error("Illegal number: %s", argv[1]); mask = (mask << 3) + (*ap - '0'); } while (*++ap != '\0'); umask(mask); } else { void *set; if ((set = setmode (ap)) == 0) error("Illegal number: %s", ap); mask = getmode (set, ~mask & 0777); umask(~mask & 0777); } @ 1.5 log @Add RCS identifiers. @ text @d39 1 a39 1 static char rcsid[] = "$Id: $"; d92 1 a92 1 if ((ap = argptr) == NULL) @ 1.4 log @Make umask builtin of shell POSIX 1003.2 compliant: Print out a symbolic mask with the -S option; and accept symbolic mask specifications. @ text @d38 2 a39 2 static char sccsid[] = "@@(#)miscbltin.c 5.2 (Berkeley) 3/13/91"; static char rcsid[] = "$Header: /b/source/CVS/src/bin/sh/miscbltin.c,v 1.3 1993/03/23 00:28:32 cgd Exp $"; @ 1.3 log @changed "Id" to "Header" for rcsids @ text @d39 1 a39 1 static char rcsid[] = "$Header: miscbltin.c,v 1.2 93/03/22 08:11:32 cgd Exp $"; d46 2 d149 3 a152 1 char *p; d154 5 d160 40 a199 6 if ((p = argv[1]) == NULL) { INTOFF; mask = umask(0); umask(mask); INTON; out1fmt("%.4o\n", mask); /* %#o might be better */ d201 16 a216 7 mask = 0; do { if ((unsigned)(i = *p - '0') >= 8) error("Illegal number: %s", argv[1]); mask = (mask << 3) + i; } while (*++p != '\0'); umask(mask); @ 1.2 log @added rcs ids to all files @ text @d39 1 a39 1 static char rcsid[] = "$Id: miscbltin.c,v 1.2 93/03/21 22:15:11 cgd Exp $"; @ 1.1 log @Initial revision @ text @d39 1 @ 1.1.1.1 log @initial import of 386bsd-0.1 sources @ text @@ 1.1.1.2 log @44lite code @ text @d2 2 a3 2 * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. d38 1 a38 1 static char sccsid[] = "@@(#)miscbltin.c 8.2 (Berkeley) 4/16/94"; d89 1 a89 1 if (*(ap = argptr) == NULL) @