Debian Codegraph @

upstream/debian-unstable/man3/NDBM_File.3perl

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\" ========================================================================
56 .\"
57 .IX Title "NDBM_File 3perl"
58 .TH NDBM_File 3perl 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide"
59 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
60 .\" way too many mistakes in technical documents.
61 .if n .ad l
62 .nh
63 .SH NAME
64 NDBM_File \- Tied access to ndbm files
65 .SH SYNOPSIS
66 .IX Header "SYNOPSIS"
67 .Vb 2
68 \& use Fcntl; # For O_RDWR, O_CREAT, etc.
69 \& use NDBM_File;
70 \&
71 \& tie(%h, \*(AqNDBM_File\*(Aq, \*(Aqfilename\*(Aq, O_RDWR|O_CREAT, 0666)
72 \& or die "Couldn\*(Aqt tie NDBM file \*(Aqfilename\*(Aq: $!; aborting";
73 \&
74 \& # Now read and change the hash
75 \& $h{newkey} = newvalue;
76 \& print $h{oldkey};
77 \& ...
78 \&
79 \& untie %h;
80 .Ve
81 .SH DESCRIPTION
82 .IX Header "DESCRIPTION"
83 \&\f(CW\*(C`NDBM_File\*(C'\fR establishes a connection between a Perl hash variable and
84 a file in NDBM_File format;. You can manipulate the data in the file
85 just as if it were in a Perl hash, but when your program exits, the
86 data will remain in the file, to be used the next time your program
87 runs.
88 .PP
89 Use \f(CW\*(C`NDBM_File\*(C'\fR with the Perl built-in \f(CW\*(C`tie\*(C'\fR function to establish
90 the connection between the variable and the file. The arguments to
91 \&\f(CW\*(C`tie\*(C'\fR should be:
92 .IP 1. 4
93 The hash variable you want to tie.
94 .IP 2. 4
95 The string \f(CW"NDBM_File"\fR. (Ths tells Perl to use the \f(CW\*(C`NDBM_File\*(C'\fR
96 package to perform the functions of the hash.)
97 .IP 3. 4
98 The name of the file you want to tie to the hash.
99 .IP 4. 4
100 Flags. Use one of:
101 .RS 4
102 .ie n .IP """O_RDONLY""" 2
103 .el .IP \f(CWO_RDONLY\fR 2
104 .IX Item "O_RDONLY"
105 Read-only access to the data in the file.
106 .ie n .IP """O_WRONLY""" 2
107 .el .IP \f(CWO_WRONLY\fR 2
108 .IX Item "O_WRONLY"
109 Write-only access to the data in the file.
110 .ie n .IP """O_RDWR""" 2
111 .el .IP \f(CWO_RDWR\fR 2
112 .IX Item "O_RDWR"
113 Both read and write access.
114 .RE
115 .RS 4
116 .Sp
117 If you want to create the file if it does not exist, add \f(CW\*(C`O_CREAT\*(C'\fR to
118 any of these, as in the example. If you omit \f(CW\*(C`O_CREAT\*(C'\fR and the file
119 does not already exist, the \f(CW\*(C`tie\*(C'\fR call will fail.
120 .RE
121 .IP 5. 4
122 The default permissions to use if a new file is created. The actual
123 permissions will be modified by the user's umask, so you should
124 probably use 0666 here. (See "umask" in perlfunc.)
125 .SH DIAGNOSTICS
126 .IX Header "DIAGNOSTICS"
127 On failure, the \f(CW\*(C`tie\*(C'\fR call returns an undefined value and probably
128 sets \f(CW$!\fR to contain the reason the file could not be tied.
129 .ie n .SS """ndbm store returned \-1, errno 22, key ""..."" at ..."""
130 .el .SS "\f(CWndbm store returned \-1, errno 22, key ""..."" at ...\fP"
131 .IX Subsection "ndbm store returned -1, errno 22, key ""..."" at ..."
132 This warning is emitted when you try to store a key or a value that
133 is too long. It means that the change was not recorded in the
134 database. See BUGS AND WARNINGS below.
135 .SH "SECURITY AND PORTABILITY"
136 .IX Header "SECURITY AND PORTABILITY"
137 \&\fBDo not accept NDBM files from untrusted sources.\fR
138 .PP
139 On modern Linux systems these are typically GDBM files, which are not
140 portable across platforms.
141 .PP
142 The GDBM documentation doesn't imply that files from untrusted sources
143 can be safely used with \f(CW\*(C`libgdbm\*(C'\fR.
144 .PP
145 Systems that don't use GDBM compatibilty for ndbm support will be
146 using a platform specific library, possibly inherited from BSD
147 systems, where it may or may not be safe to use an untrusted file.
148 .PP
149 A maliciously crafted file might cause perl to crash or even expose a
150 security vulnerability.
151 .SH "BUGS AND WARNINGS"
152 .IX Header "BUGS AND WARNINGS"
153 There are a number of limits on the size of the data that you can
154 store in the NDBM file. The most important is that the length of a
155 key, plus the length of its associated value, may not exceed 1008
156 bytes.
157 .PP
158 See "tie" in perlfunc, perldbmfilter, Fcntl