Debian Codegraph @

upstream/mageia-cauldron/man3pm/NDBM_File.3pm

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man v6.0.2 (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 .\" Required to disable full justification in groff 1.23.0.
57 .if n .ds AD l
58 .\" ========================================================================
59 .\"
60 .IX Title "NDBM_File 3pm"
61 .TH NDBM_File 3pm 2025-06-24 "perl v5.42.0" "Perl Programmers Reference Guide"
62 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
63 .\" way too many mistakes in technical documents.
64 .if n .ad l
65 .nh
66 .SH NAME
67 NDBM_File \- Tied access to ndbm files
68 .SH SYNOPSIS
69 .IX Header "SYNOPSIS"
70 .Vb 2
71 \& use Fcntl; # For O_RDWR, O_CREAT, etc.
72 \& use NDBM_File;
73 \&
74 \& tie(%h, \*(AqNDBM_File\*(Aq, \*(Aqfilename\*(Aq, O_RDWR|O_CREAT, 0666)
75 \& or die "Couldn\*(Aqt tie NDBM file \*(Aqfilename\*(Aq: $!; aborting";
76 \&
77 \& # Now read and change the hash
78 \& $h{newkey} = newvalue;
79 \& print $h{oldkey};
80 \& ...
81 \&
82 \& untie %h;
83 .Ve
84 .SH DESCRIPTION
85 .IX Header "DESCRIPTION"
86 \&\f(CW\*(C`NDBM_File\*(C'\fR establishes a connection between a Perl hash variable and
87 a file in NDBM_File format;. You can manipulate the data in the file
88 just as if it were in a Perl hash, but when your program exits, the
89 data will remain in the file, to be used the next time your program
90 runs.
91 .PP
92 Use \f(CW\*(C`NDBM_File\*(C'\fR with the Perl built\-in \f(CW\*(C`tie\*(C'\fR function to establish
93 the connection between the variable and the file. The arguments to
94 \&\f(CW\*(C`tie\*(C'\fR should be:
95 .IP 1. 4
96 The hash variable you want to tie.
97 .IP 2. 4
98 The string \f(CW"NDBM_File"\fR. (Ths tells Perl to use the \f(CW\*(C`NDBM_File\*(C'\fR
99 package to perform the functions of the hash.)
100 .IP 3. 4
101 The name of the file you want to tie to the hash.
102 .IP 4. 4
103 Flags. Use one of:
104 .RS 4
105 .ie n .IP """O_RDONLY""" 2
106 .el .IP \f(CWO_RDONLY\fR 2
107 .IX Item "O_RDONLY"
108 Read\-only access to the data in the file.
109 .ie n .IP """O_WRONLY""" 2
110 .el .IP \f(CWO_WRONLY\fR 2
111 .IX Item "O_WRONLY"
112 Write\-only access to the data in the file.
113 .ie n .IP """O_RDWR""" 2
114 .el .IP \f(CWO_RDWR\fR 2
115 .IX Item "O_RDWR"
116 Both read and write access.
117 .RE
118 .RS 4
119 .Sp
120 If you want to create the file if it does not exist, add \f(CW\*(C`O_CREAT\*(C'\fR to
121 any of these, as in the example. If you omit \f(CW\*(C`O_CREAT\*(C'\fR and the file
122 does not already exist, the \f(CW\*(C`tie\*(C'\fR call will fail.
123 .RE
124 .IP 5. 4
125 The default permissions to use if a new file is created. The actual
126 permissions will be modified by the user\*(Aqs umask, so you should
127 probably use 0666 here. (See "umask" in perlfunc.)
128 .SH DIAGNOSTICS
129 .IX Header "DIAGNOSTICS"
130 On failure, the \f(CW\*(C`tie\*(C'\fR call returns an undefined value and probably
131 sets \f(CW$!\fR to contain the reason the file could not be tied.
132 .ie n .SS """ndbm store returned \-1, errno 22, key ""..."" at ..."""
133 .el .SS "\f(CWndbm store returned \-1, errno 22, key ""..."" at ...\fP"
134 .IX Subsection "ndbm store returned -1, errno 22, key ""..."" at ..."
135 This warning is emitted when you try to store a key or a value that
136 is too long. It means that the change was not recorded in the
137 database. See BUGS AND WARNINGS below.
138 .SH "SECURITY AND PORTABILITY"
139 .IX Header "SECURITY AND PORTABILITY"
140 \&\fBDo not accept NDBM files from untrusted sources.\fR
141 .PP
142 On modern Linux systems these are typically GDBM files, which are not
143 portable across platforms.
144 .PP
145 The GDBM documentation doesn\*(Aqt imply that files from untrusted sources
146 can be safely used with \f(CW\*(C`libgdbm\*(C'\fR.
147 .PP
148 Systems that don\*(Aqt use GDBM compatibility for ndbm support will be
149 using a platform specific library, possibly inherited from BSD
150 systems, where it may or may not be safe to use an untrusted file.
151 .PP
152 A maliciously crafted file might cause perl to crash or even expose a
153 security vulnerability.
154 .SH "BUGS AND WARNINGS"
155 .IX Header "BUGS AND WARNINGS"
156 There are a number of limits on the size of the data that you can
157 store in the NDBM file. The most important is that the length of a
158 key, plus the length of its associated value, may not exceed 1008
159 bytes.
160 .PP
161 See "tie" in perlfunc, perldbmfilter, Fcntl