gdbm

목차




복사 조건

This library is free; this means that everyone is free to use it and free to redistribute it on a free basis. GNU dbm (gdbm) is not in the public domain; it is copyrighted and there are restrictions on its distribution, but these restrictions are designed to permit everything that a good cooperating citizen would want to do. What is not allowed is to try to prevent others from further sharing any version of gdbm that they might get from you.

Specifically, we want to make sure that you have the right to give away copies gdbm, that you receive source code or else can get it if you want it, that you can change these functions or use pieces of them in new free programs, and that you know you can do these things.

이 라이브러리는 자유롭다. 이는 아무나 사용할 수 있고, 이 조건하에서 자유롭게 배포할 수 있다는 뜻이다. GNU dbm (gdbm)는 퍼블릭 도메인(public domain)에 있지 않다. (즉, 이를 상업적인 목적으로 배타적으로 사용할 수 없다.) 이는 저작권으로 보호되고 배포하는데 제한이 있다. 그러나 이 제한은 협동하는 좋은 네티즌이 하려는 모든 것을 허용하기 위해 의도됬다. 허용되지 않는 것은 다른 사람들과 더 이상 gdbm을 공유하지 않으려 하는 것이다.

당신에게 gdbm을 배포할 권리와 원한다면 소스코드 등을 얻을 권리가 있음을 명확히 한다. 그래서 기능을 수정하거나 새로운 자유 소프트웨어에서 코드의 일부를 사용할 수 있다는 점을 알아야 한다.

To make sure that everyone has such rights, we have to forbid you to deprive anyone else of these rights. For example, if you distribute copies gdbm, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights.

Also, for our own protection, we must make certain that everyone finds out that there is no warranty for anything in the gdbm distribution. If these functions are modified by someone else and passed on, we want their recipients to know that what they have is not what we distributed, so that any problems introduced by others will not reflect on our reputation.

모두에게 이런 권리가 있기 때문에 우리는 당신이 그들에게서 이 권리를 빼았는 것을 금지한다. 예를 들어 당신이 gdbm을 배포한다면 당신이 가진 권리도 줘야한다. 또 그들이 소스코드를 얻을 수 있다는 것도 알려야한다. 그들에게 그들의 권리를 말해줘야 한다.

또한 우리는 gdbm 배포를 보장하지 않는다는 점도 확실히 한다. 어떤 사람이 기능을 수정하였다면 우리가 원래 배포한 것이 아님을 알려서, 다른 사람이 만든 문제로 우리 명성에 영향이 없어야 한다.

gdbm is currently distributed under the terms of the GNU General Public License, Version 2. (NOT under the GNU General Library Public License.) A copy the GNU General Public License is included with the distribution of gdbm.

gdbm은 현재 (GNU General Library Public License가 아니라) GNU General Public License, Version 2로 배포된다. GNU General Public License의 복사본은 gdbm에 포함되있다. (역주; 즉, 상업적 목적의 소프트웨어에서 gdbm을 사용할 수 없다.)

GNU dbm 소개

GNU dbm (gdbm)is a library of database functions that use extendible hashing and works similar to the standard UNIX dbm functions. These routines are provided to a programmer needing to create and manipulate a hashed database. (gdbm is NOT a complete database package for an end user.)

The basic use of gdbm is to store key/data pairs in a data file. Each key must be unique and each key is paired with only one data item. The keys can not be directly accessed in sorted order. The basic unit of data in gdbm is the structure:

 typedef struct { char *dptr; int dsize; } datum; 

GNU dbm(gdbm)은 확장가능한 해쉬를 사용한 데이터베이스 함수 라이브러리로, 표준 유닉스 dbm 함수와 비슷하게 동작한다. 이 함수들로 해쉬된 데이터베이스를 만들고 다룰 수 있다. (dbm은 일반 사용자를 위한 완전한 데이테베이스가 아니다.)

gdbm은 기본적으로 자료 파일에 키와 자료의 쌍을 저장한다. 각 키는 중복되면 안되고, 오직 하나의 자료를 가진다. 키는 정렬된 순서로 직접 접근할 수 없다. gdbm의 (키와 자료의) 기본 자료구조는 다음과 같다.

 typedef struct { char *dptr; int dsize; } datum; 

This structure allows for arbitrary sized keys and data items.

The key/data pairs are stored in a gdbm disk file, called a gdbm database. An application must open a gdbm database to be able manipulate the keys and data contained in the database. gdbm allows an application to have multiple databases open at the same time. When an application opens a gdbm database, it is designated as a reader or a writer. A gdbm database opened by at most one writer at a time. However, many readers may open the database open simultaneously. Readers and writers can not open the gdbm database at the same time.

이 구조체는 어떤 크기의 키와 자료도 담을 수 있다.

키와 자료 쌍은 gdbm 데이터베이스라고 부르는 gdbm 자료 파일에 저장된다. 프로그램은 데이터베이스에 저장된 키와 자료를 다루기 위해서 gdbm 데이터베이스를 열어야 한다. gdbm에서 프로그램은 동시에 여러 데이터베이스를 열 수 있다. 프로그램이 gdbm 데이터베이스를 열면, 독자(reader)필자(writer)로 행동한다. gdbm 데이터베이스는 동시에 최대 한 필자만이 열 수 있지만, 독자의 경우 여러 독자가 동시에 한 데이터베이스를 열 수 있다. 독자와 필자는 동시에 gdbm 데이터베이스를 열 수 없다.

함수 목록

The following is a quick list of the functions contained in the gdbm library. The include file gdbm.h, that can be included by the user, contains a definition of these functions.

#include <gdbm.h> GDBM_FILE gdbm_open(name, block_size, flags, mode, fatal_func); void gdbm_close(dbf); int gdbm_store(dbf, key, content, flag); datum gdbm_fetch(dbf, key); int gdbm_delete(dbf, key); datum gdbm_firstkey(dbf); datum gdbm_nextkey(dbf, key); int gdbm_reorganize(dbf); void gdbm_sync(dbf); int gdbm_exists(dbf, key); char *gdbm_strerror(errno); int gdbm_setopt(dbf, option, value, size); int gdbm_fdesc(dbf); 

다음은 gdbm 라이브러리에 포함된 함수들이다. 헤더 파일 gdbm.h에 이 함수들이 선언되있다.

#include <gdbm.h> GDBM_FILE gdbm_open(name, block_size, flags, mode, fatal_func); void gdbm_close(dbf); int gdbm_store(dbf, key, content, flag); datum gdbm_fetch(dbf, key); int gdbm_delete(dbf, key); datum gdbm_firstkey(dbf); datum gdbm_nextkey(dbf, key); int gdbm_reorganize(dbf); void gdbm_sync(dbf); int gdbm_exists(dbf, key); char *gdbm_strerror(errno); int gdbm_setopt(dbf, option, value, size); int gdbm_fdesc(dbf); 

The gdbm.h include file is often in the `/usr/local/include' directory. (The actual location of gdbm.h depends on your local installation of gdbm.)
헤더 파일 gdbm.h는 보통 `/usr/local/include'에 있다. (gdbm.h의 실제 위치는 gdbm을 구성한 방법에 따라 다르다.)

데이터베이스 열기

Initialize gdbm system. If the file has a size of zero bytes, a file initialization procedure is performed, setting up the initial structure in the file.

The procedure for opening a gdbm file is:

GDBM_FILE dbf; dbf = gdbm_open(name, block_size, flags, mode, fatal_func); 

gdbm 시스템을 초기화한다. 파일의 크기가 0이라면 파일에 초기 구조를 만드는 파일 초기화 과정이 수행된다.

gdbm 파일을 여는 함수는,

GDBM_FILE dbf; dbf = gdbm_open(name, block_size, flags, mode, fatal_func); 

The parameters are:

파라미터는 다음과 같다.

char *name
The name of the file (the complete name, gdbm does not append any characters to this name).
파일명. (완전한 이름, gdbm은 이 이름에 어떤 문자도 추가하지 않는다.)
int block_size
It is used during initialization to determine the size of various constructs. It is the size of a single transfer from disk to memory. This parameter is ignored if the file has been previously initialized. The minimum size is 512. If the value is less than 512, the file system blocksize is used, otherwise the value of block_size is used.
초기화시 여러 구조의 크기를 판단할 때 사용한다. 이는 디스크에서 메모리로 한번에 옮길 수 있는 크기이다. 파일이 이미 초기화되었다면, 이 파라미터는 무시된다. 최소값은 512이다. 512 보다 작다면 대신 파일시스템 블럭크기가 사용된다.
int flags
If flags is set to GDBM_READER, the user wants to just read the database and any call to gdbm_store or gdbm_delete will fail. Many readers can access the database at the same time. If flags is set to GDBM_WRITER, the user wants both read and write access to the database and requires exclusive access. If flags is set to GDBM_WRCREAT, the user wants both read and write access to the database and if the database does not exist, create a new one. If flags is set to GDBM_NEWDB, the user want a new database created, regardless of whether one existed, and wants read and write access to the new database. The following may also be logically or'd into the database flags: GDBM_SYNC, which causes all database operations to be synchronized to the disk, and GDBM_NOLOCK, which prevents the library from performing any locking on the database file. The option GDBM_FAST is now obsolete, since gdbm defaults to no-sync mode. Any error detected will cause a return value of NULL and an appropriate value will be in gdbm_errno (see Variables). If no errors occur, a pointer to the gdbm file descriptor will be returned.
flags가 GDBM_READER라면 사용자는 데이터베이스를 읽기만 한다. gdbm_storegdbm_delete 함수는 실패한다. 동시에 많은 독자가 데이테베이스에 접근할 수 있다. flags가 GDBM_WRITER라면 사용자는 데이터베이스를 읽고 쓸 수 있다. 그러면 다른 것들은 데이터베이스에 접근할 수 없게 된다. flags가 GDBM_WRCREAT이면 사용자는 데이터베이스를 읽고 쓸 수 있고, 만약 데이터베이스가 없다면 새로 만든다. flags가 GDBM_NEWDB라면 사용자는 이미 있더라도 새롭게 데이터베이스를 만들고, 데이터베이스를 읽고 쓸 수 있다. 다음은 위의 값들과 논리합(OR)을 할 수 있다. GDBM_SYNC는 모든 데이터베이스 작업을 디스크과 동기화한다. GDBM_NOLOCK은 라이브러리가 데이터베이스 파일을 잠그지 않게 한다. GDBM_FAST는 동기화하지 않는 것이 기본 행동이기 때문에 지금은 사용되지 않는다. 어떤 오류가 발생하면 NULL을 반환하고, 적절한 값이 gdbm_errno에 저장된다. ("두 유용한 변수" 참고) 오류가 없다면 gdbm 파일기술자의 포인터가 반환된다.
int mode
File mode (see chmod(2) and open(2) if the file is created).
파일 모드. (파일이 생성될 때 사용된다. chmod(2)와 open(2) 참고)
void (*fatal_func) ()
A function for gdbm to call if it detects a fatal error. The only parameter of this function is a string. If the value of NULL is provided, gdbm will use a default function.
심각한 오류가 발생했을 때 호출하는 함수. 이 함수는 문자열의 한 아규먼트를 받는다. NULL을 사용하면 기본 함수가 사용된다. (역주; 기본 함수는 "gdbm fatal: " 뒤에 문자열을 출력하고 줄바꿈을 한다.)

The return value, dbf, is the pointer needed by all other functions to access that gdbm file. If the return is the NULL pointer, gdbm_open was not successful. The errors can be found in gdbm_errno for gdbm errors and in errno for file system errors (for error codes, see gdbm.h).

In all of the following calls, the parameter dbf refers to the pointer returned from gdbm_open.

반환값 dbfgdbm 파일을 접근하는 다른 모든 함수들이 필요로하는 포인터이다. NULL 포인터를 반환하면, gdbm_open은 성공하지 못한 것이다. gdbm 오류는 gdbm_errno, 파일시스템 오류는 errno에서 찾을 수 있다. (오류 코드는 gdbm.h를 참고하라.)

다음 모든 함수에서 파라미터 dbfgdbm_open이 반환한 포인터이다.

데이터베이스 닫기

It is important that every file opened is also closed. This is needed to update the reader/writer count on the file. This is done by:

gdbm_close(dbf); 

한번 열었던 파일을 닫는 것은 중요하다. 닫기는 파일에 변경된 독자와 필자 수를 반영하기 위해 필요하다. 닫기는 다음 함수로 한다.

gdbm_close(dbf); 

The parameter is:

파라미터는 다음과 같다.

GDBM_FILE dbf
The pointer returned by gdbm_open.
gdbm_open이 반환한 포인터.

Closes the gdbm file and frees all memory associated with the file dbf.
이 함수는 gdbm 파일을 닫고, dbf 파일과 연관된 모든 메모리를 반환한다.

데이터베이스에서 레코드 추가/대체

The function gdbm_store inserts or replaces records in the database.

ret = gdbm_store(dbf, key, content, flag); 

함수 gdbm_store는 데이터베이스에서 레코드를 추가하거나 대체한다.

ret = gdbm_store(dbf, key, content, flag); 

The parameters are:
파라미터는 다음과 같다.

GDBM_FILE dbf
The pointer returned by gdbm_open.
gdbm_open이 반환한 포인터.
datum key
The key data.
키.
datum content
The data to be associated with the key.
키와 연결된 자료.
int flag
Defines the action to take when the key is already in the database. The value GDBM_REPLACE (defined in gdbm.h) asks that the old data be replaced by the new content. The value GDBM_INSERT asks that an error be returned and no action taken if the key already exists.
키가 이미 데이터베이스에 있을 때 취할 행동을 결정한다. (gdbm.h에 정의된) GDBM_REPLACE를 사용하면 새로운 content로 전의 자료를 대체한다. GDBM_INSERT를 사용하면 이미 key가 있는 경우 오류를 발생하고 아무 일도 하지 않는다.

The values returned in ret are:
반환값 ret는,

-1
The item was not stored in the database because the caller was not an official writer or either key or content have a NULL dptr field. Both key and content must have the dptr field be a non-NULL value. Since a NULL dptr field is used by other functions to indicate an error, a NULL field cannot be valid data.
함수를 부른 사람이 공식 저자가 아니거나 keycontent 구조체의 dptr 멤버가 NULL이기 때문에 데이터베이스에 저장할 수 없다. keycontent 구조체의 dptr 멤버는 NULL이 아닌 값을 가져야한다. dptr 값이 NULL인 것은 다른 함수에서 오류를 의미하기 때문에 사용할 수 없다.
+1
The item was not stored because the argument flag was GDBM_INSERT and the key was already in the database.
flag가 GDBM_INSERT이고 key가 이미 데이터베이스에 있기 때문에 베이터베이스에 저장할 수 없다.
0
No error. content is keyed by key. The file on disk is updated to reflect the structure of the new database before returning from this function.
오류 없음. key를 키로 하여 content가 저장되었다. 이 함수가 반환하기 전에, 디스크의 파일은 새로운 데이터베이스 구조를 반영하기 위해 갱신된다.

If you store data for a key that is already in the data base, gdbm replaces the old data with the new data if called with GDBM_REPLACE. You do not get two data items for the same key and you do not get an error from gdbm_store.

The size in gdbm is not restricted like dbm or ndbm. Your data can be as large as you want.

이미 있는 key로 자료를 저장하려할 때, GDBM_REPLACE를 사용한 경우 새로운 자료로 기존의 자료를 대체한다. 이 경우 같은 key에 두 자료가 저장되지 않고, 문제없이 실행된다.

gdbm에서 크기는 dbmndbm과 같이 제한되지 않는다. 자료는 원하는 만큼 커질 수 있다.

데이터베이스에서 레코드 찾기

Looks up a given key and returns the information associated with that key. The pointer in the structure that is returned is a pointer to dynamically allocated memory block. To search for some data:

content = gdbm_fetch(dbf, key); 

주어진 key를 찾고, 그 키와 연결된 자료를 반환한다. 반환되는 구조체의 포인터는 동적으로 할당된 메모리를 가리킨다. 자료를 찾기 위해서 다음 함수를 사용한다.

content = gdbm_fetch(dbf, key); 

The parameters are:
파라미터는 다음과 같다.

GDBM_FILE dbf
The pointer returned by gdbm_open.
gdbm_open이 반환한 포인터.
datum key
The key data.
키.

The datum returned in content is a pointer to the data found. If the dptr is NULL, no data was found. If dptr is not NULL, then it points to data allocated by malloc. gdbm does not automatically free this data. The user must free this storage when done using it. This eliminates the need to copy the result to save it for later use (you just save the pointer).

content로 반환된 자료는 찾은 자료의 포인터이다. dptr이 NULL이라면 자료를 찾지 못한 것이다. dptr이 NULL이 아니라면 malloc으로 할당한 공간의 포인터이다. gdbm는 자동으로 이 공간를 반환하지 않는다. 사용자는 사용한 후 이 공간을 반환해야 한다. 이런 방식은 (dbm이나 ndbm과 달리) 나중에 사용하기 위해 결과를 저장할 필요를 없게한다. (단지 포인터만 저장하면 된다.) (역주; datum 구조체의 포인터가 반환되지 않음을 주의하라. gdbm_fetch는 단지 dptr을 위한 메모리만을 동적으로 할당한다. 만약 키와 연결된 자료가 크기가 없다면 dsize 멤버는 0이지만, dptr은 NULL이 아니기 위해서 크기가 1로 할당된 메모리를 가리킨다. 반대로 gdbm_store의 경우에도 크기가 0인 자료를 키나 자료로 사용할 수 있다. datum.dsize = 0; datum.dptr = "";과 같이 하면 된다.)

You may also search for a particular key without retrieving it, using:

ret = gdbm_exists(dbf, key); 

또한 다음 함수를 사용하여 자료를 가져오지 않고 특정 키의 유무만을 알아볼 수도 있다.

ret = gdbm_exists(dbf, key); 

The parameters are:
파라미터는 다음과 같다.

GDBM_FILE dbf
The pointer returned by gdbm_open.
gdbm_open이 반환한 포인터.
datum key
The key data.
키.

Unlike gdbm_fetch, this routine does not allocate any memory, and simply returns true or false, depending on whether the key exists, or not.
gdbm_fetch와 달리 이 함수는 메모리를 할당하지 않고, 단지 key의 존재 유무만을 알려준다.

데이터베이스에서 레코드 삭제하기

To remove some data from the database:

ret = gdbm_delete(dbf, key); 

데이터베이스에서 자료를 삭제하려면 다음 함수를 사용한다.
ret = gdbm_delete(dbf, key); 

The parameters are:
파라미터는 다음과 같다.

GDBM_FILE dbf
The pointer returned by gdbm_open.
gdbm_open이 반환한 포인터.
datum key
The key data.
키.

The ret value is -1 if the item is not present or the requester is a reader. The ret value is 0 if there was a successful delete.

gdbm_delete removes the keyed item and the key from the database dbf. The file on disk is updated to reflect the structure of the new database before returning from this function.

자료가 없거나 독자가 함수를 부른 경우 -1이 반환된다. 성공적으로 삭제하였다면 0을 반환한다.

gdbm_delete는 데이터베이스 dbf에서 key와, 연결된 자료를 삭제한다. 이 함수가 반환하기 전에, 디스크의 파일은 새로운 데이터베이스 구조를 반영하기 위해 갱신된다.

레코드를 순차적으로 접근하기

The next two functions allow for accessing all items in the database. This access is not key sequential, but it is guaranteed to visit every key in the database once. The order has to do with the hash values. gdbm_firstkey starts the visit of all keys in the database. gdbm_nextkey finds and reads the next entry in the hash structure for dbf.

key = gdbm_firstkey(dbf); nextkey = gdbm_nextkey(dbf, key); 

다음 두 함수는 데이터베이스의 모든 키를 접근할 때 사용한다. 이는 key를 순차적으로 접근하지는 않지만, 데이터베이스의 모든 key를 한번씩 접근하는 것을 보장한다. 접근 순서는 헤쉬값과 관련이 있다. gdbm_firstkey는 데이터베이스의 모든 키의 접근을 시작한다. gdbm_nextkeydbf의 해쉬 구조에서 다음 레코드를 찾아서 반환한다.

key = gdbm_firstkey(dbf); nextkey = gdbm_nextkey(dbf, key); 

The parameters are:
파라미터는 다음과 같다.

GDBM_FILE dbf
The pointer returned by gdbm_open.
gdbm_open이 반환한 포인터.
datum key
datum nextkey
The key data.
키.

The return values are both datum. If key.dptr or nextkey.dptr is NULL, there is no first key or next key. Again notice that dptr points to data allocated by malloc and gdbm will not free it for you.

These functions were intended to visit the database in read-only algorithms, for instance, to validate the database or similar operations.

반환된 값은 모두 datum 구조체이다. key.dptr나 nextkey.dptr이 NULL이라면 첫 key나 다음 key가 없는 것이다. 다시 dptr 포인터는 malloc으로 할당한 공간을 가리키며, gdbm는 이를 알아서 반환하지 않는 점을 주의하라.

이 함수들은 데이터베이스 확인 등의 작업을 위해 읽기전용으로 데이터베이스를 접근함을 가정한다.

File visiting is based on a hash table. gdbm_delete re-arranges the hash table to make sure that any collisions in the table do not leave some item un-findable. The original key order is NOT guaranteed to remain unchanged in ALL instances. It is possible that some key will not be visited if a loop like the following is executed:

 key = gdbm_firstkey ( dbf ); while ( key.dptr ) { nextkey = gdbm_nextkey ( dbf, key ); if ( some condition ) { gdbm_delete ( dbf, key ); free ( key.dptr ); } key = nextkey; } 

방문하는 파일은 해쉬테이블을 기반으로 한다. gdbm_delete는 테이블의 어떤 불일치가 자료를 찾을 수 없게 만들지 않게하기 위해서 해쉬테이블을 재정렬한다. 원래 키 순서가 그대로 유지된다고 보장하지 못한다. 다음과 같은 (데이터베이스를 수정하는) 반복문에서 어떤 키는 접근하지 못할 수도 있다.

 key = gdbm_firstkey ( dbf ); while ( key.dptr ) { nextkey = gdbm_nextkey ( dbf, key ); if ( some condition ) { gdbm_delete ( dbf, key ); free ( key.dptr ); } key = nextkey; } 

데이터베이스 재구성

The following function should be used very seldom.

ret = gdbm_reorganize(dbf); 

다음 함수는 매우 드물게 사용해야 한다.

ret = gdbm_reorganize(dbf); 

The parameter is:
파라미터는 다음과 같다.

GDBM_FILE dbf
The pointer returned by gdbm_open.
gdbm_open이 반환한 포인터.

If you have had a lot of deletions and would like to shrink the space used by the gdbm file, this function will reorganize the database. gdbm will not shorten the length of a gdbm file (deleted file space will be reused) except by using this reorganization.

This reorganization requires creating a new file and inserting all the elements in the old file dbf into the new file. The new file is then renamed to the same name as the old file and dbf is updated to contain all the correct information about the new file. If an error is detected, the return value is negative. The value zero is returned after a successful reorganization.

매우 많이 삭제한 후 gdbm 파일이 사용하는 공간을 줄이고 싶을 때, 이 함수로 데이터베이스를 재구성한다. gdbm는 이 재구성 외의 경우에는 gdbm 파일 크기를 줄이지 않는다. (삭제한 후 남은 파일 공간은 재사용된다.)

재구성은 새로 파일을 만들고 기존의 dbf 파일의 모든 자료를 새 파일에 집어넣는다. 그후 새 파일은 처음 파일과 같은 이름으로 변경되고, dbf는 새 파일에 대한 정보로 갱신된다. 오류가 발생하면 반환값은 음수이다. 성공적으로 재구성을 마쳤다면 0을 반환한다.

데이터베이스 동기화

Unless your database was opened with the GDBM_SYNC flag, gdbm does not wait for writes to be flushed to the disk before continuing. This allows faster writing of databases at the risk of having a corrupted database if the application terminates in an abnormal fashion. The following function allows the programmer to make sure the disk version of the database has been completely updated with all changes to the current time.

gdbm_sync(dbf); 

데이터베이스를 GDBM_SYNC 플래그로 열지 않았다면, gdbm은 자료가 디스크에 쓰여지는 것을 기다리지 않는다. 그래서 빨리 데이테베이스에 쓸 수 있지만, 프로그램이 비정상적으로 종료하는 경우 데이터베이스를 망가트릴 수 있다. 다음 함수는 현재까지 모든 변화가 디스크에 완전히 기록되었음을 보장한다.

gdbm_sync(dbf); 

The parameter is:
파라미터는 다음과 같다.

GDBM_FILE dbf
The pointer returned by gdbm_open.
gdbm_open이 반환한 포인터.

This would usually be called after a complete set of changes have been made to the database and before some long waiting time. gdbm_close automatically calls the equivalent of gdbm_sync so no call is needed if the database is to be closed immediately after the set of changes have been made.
이 함수는 보통 데이터베이스에 일련의 변화를 준 후, 오래동안 쉬기 전에 사용한다. gdbm_close는 자동으로 gdbm_sync와 비슷한 작업을 하기 때문에 변화후 즉시 데이터베이스를 닫는다면 이 함수를 사용할 필요는 없다.

오류 문자열

To convert a gdbm error code into English text, use this routine:

ret = gdbm_strerror(errno) 

다음 함수는 gdbm 오류 코드를 영어 문장으로 바꾼다.
ret = gdbm_strerror(errno) 

The parameter is:
파라미터는 다음과 같다.

gdbm_error errno
The gdbm error code, usually gdbm_errno.
gdbm 오류 코드, 보통 gdbm_errno.

The appropiate phrase for reading by humans is returned.

사람이 알아볼 수 있는 문구가 반환된다.

옵션 설정하기

Gdbm supports the ability to set certain options on an already open database.

ret = gdbm_setopt(dbf, option, value, size); 

다음 함수를 사용하여 이미 연 데이터베이스에 옵션을 설정할 수 있다.
ret = gdbm_setopt(dbf, option, value, size); 

The parameters are:

GDBM_FILE dbf
The pointer returned by gdbm_open.
gdbm_open이 반환한 포인터.
int option
The option to be set.
설정할 옵션.
int *value
A pointer to the value to which option will be set.
option 값으로 사용할 자료의 포인터.
int size
The length of the data pointed to by value.
value 포인터가 가리키는 자료의 크기.

The valid options are:
가능한 옵션은 다음과 같다.

GDBM_CACHESIZE - Set the size of the internal bucket cache. This option may only be set once on each GDBM_FILE descriptor, and is set automatically to 100 upon the first access to the database.
GDBM_CACHESIZE - 내부 버킷(bucket) 캐쉬의 크기를 설정한다. 이 옵션은 각 GDBM_FILE 기술자에 한번만 사용할 수 있고, 데이터베이스에 처음 접근할 때 자동으로 100으로 설정된다.

GDBM_FASTMODE - Set fast mode to either on or off. This allows fast mode to be toggled on an already open and active database. value (see below) should be set to either TRUE or FALSE. This option is now obsolete.
GDBM_FASTMODE - 빠른 모드를 키고 끈다. 이 옵션은 이미 열려진 데이터베이스의 빠른 모드를 키고 끈다. 값은 TRUE나 FALSE만이 가능하다. (아래 참고) 이 옵션은 현재 사용되지 않는다.

GDBM_SYNCMODE - Turn on or off file system synchronization operations. This setting defaults to off; value (see below) should be set to either TRUE or FALSE.
GDBM_SYNCMODE - 파일시스템 동기화를 키고 끈다. 기본값은 꺼져있다. 값은 TRUE나 FALSE만이 가능하다. (아래 참고)

GDBM_CENTFREE - Set central free block pool to either on or off. The default is off, which is how previous versions of Gdbm handled free blocks. If set, this option causes all subsequent free blocks to be placed in the global pool, allowing (in theory) more file space to be reused more quickly. value (see below) should be set to either TRUE or FALSE. NOTICE: This feature is still under study.
GDBM_CENTFREE - 중앙 프리블럭 풀(free block pool)을 키고 끈다. 기본값은 꺼져있다. 이는 과거 gdbm이 프리블럭을 다루는 방법이었다. 이 옵션을 키면 이후 모든 프리블럭을 전역 풀에 두어서 (이론적으로) 더 많은 파일공간이 빨리 재사용되게 한다. 값은 TRUE나 FALSE만이 가능하다. (아래 참고) 주의: 이 기능은 현재 연구중이다.

GDBM_COALESCEBLKS - Set free block merging to either on or off. The default is off, which is how previous versions of Gdbm handled free blocks. If set, this option causes adjacent free blocks to be merged. This can become a CPU expensive process with time, though, especially if used in conjunction with GDBM_CENTFREE. value (see below) should be set to either TRUE or FALSE. NOTICE: This feature is still under study.
GDBM_COALESCEBLKS - 프리블럭 합치기를 키고 끈다. 기본값은 꺼져있다. 이는 과거 gdbm이 프리블럭을 다루는 방법이었다. 이 옵션을 키면 이웃한 프리블럭들을 합친다. 그러나 이 작업은 (특히 GDBM_CENTFREE와 함께 사용하면) CPU 자원을 많이 차지한다. 값은 TRUE나 FALSE만이 가능하다. (아래 참고)

The return value will be -1 upon failure, or 0 upon success. The global variable gdbm_errno will be set upon failure.

For instance, to set a database to use a cache of 10, after opening it with gdbm_open, but prior to accessing it in any way, the following code could be used:

int value = 10; ret = gdbm_setopt(dbf, GDBM_CACHESIZE, &value, sizeof(int)); 

실패하면 -1, 성공하면 0이 반환된다. 실패시 전역변수 gdbm_errno가 설정된다.

예를 들어 gdbm_open으로 데이터베이스를 연 후 실제로 접근하기 전에 다음과 같이 데이터베이스의 캐쉬를 10으로 설정할 수 있다.

int value = 10; ret = gdbm_setopt(dbf, GDBM_CACHESIZE, &value, sizeof(int)); 

(역주; 위에서 TRUE나 FALSE만이 가능하다고 했는데, 이 두 값은 헤더파일에서 정의되었으므로 int value = TRUE;와 같이 사용하면 된다.)

파일 잠그기

With locking disabled (if gdbm_open was called with GDBM_NOLOCK), the user may want to perform their own file locking on the database file in order to prevent multiple writers operating on the same file simultaneously.

In order to support this, the gdbm_fdesc routine is provided.

ret = gdbm_fdesc(dbf); 

(gdbm_open에서 GDBM_NOLOCK을 사용하여) 잠그기를 안한다면 같은 파일에 동시에 여러 필자가 접근하는 것을 막기위해 직접 데이터베이스 파일을 잠글 필요가 있다.

이를 지원하기 위해 gdbm_fdesc 함수가 제공된다.

ret = gdbm_fdesc(dbf); 

The single valid parameter is:
파라미터는 다음과 같다.

GDBM_FILE dbf
The pointer returned by gdbm_open.
gdbm_open이 반환한 포인터.

The return value will be the file descriptor of the database.
데이터베이스의 파일기술자가 반환된다.

두 유용한 변수

The following two variables are variables that may need to be used:

다음 두 변수가 필요할 수 있다.

gdbm_error gdbm_errno
The variable that contains more information about gdbm errors (gdbm.h has the definitions of the error values).
gdbm 오류에 대한 정보를 저장하는 변수. (오류값의 정의는 gdbm.h에 있다.)
char * gdbm_version
The string containing the version information.
버전 정보를 저장하는 문자열.

표준 dbm, ndbm과 호환성

GNU dbm files are not sparse. You can copy them with the UNIX cp command and they will not expand in the copying process.

There is a compatibility mode for use with programs that already use UNIX dbm and UNIX ndbm.

GNU dbm has compatibility functions for dbm. For dbm compatibility functions, you need the include file dbm.h.

GNU dbm 파일은 중간이 비어있지(sparse) 않다. 그래서 유닉스 cp 명령으로 복사해도 크기가 커지지 않는다.

이미 유닉스 dbm이나 ndbm을 사용하는 프로그램을 위한 호환 모드가 있다.

GNU dbmdbm과 호환을 위한 함수를 제공한다. dbm 호환 함수는 헤더파일 dbm.h에 선언되있다.

In this compatibility mode, no gdbm file pointer is required by the user, and Only one file may be opened at a time. All users in compatibility mode are assumed to be writers. If the gdbm file is a read only, it will fail as a writer, but will also try to open it as a reader. All returned pointers in datum structures point to data that gdbm WILL free. They should be treated as static pointers (as standard UNIX dbm does). The compatibility function names are the same as the UNIX dbm function names. Their definitions follow:

int dbminit(name); int store(key, content); datum fetch(key); int delete(key); datum firstkey(); datum nextkey(key); int dbmclose(); 

호환 모드에서 gdbm 파일포인터는 사용하지 않고, 오직 한 파일만 동시에 열 수 있다. 호환 모드에서는 모든 사용자를 필자로 가정한다. gdbm 파일이 읽기전용이라면 필자이기 때문에 실패할 것이다. 그러나 독자로 파일을 열 수 있다. 반환된 datum 자료구조의 포인터는 gdbm이 알아서 반환한다. 포인터를 (표준 유닉스 dbm처럼) 정적포인터로 취급해야 한다. 호환 함수이름은 유닉스 dbm과 같다. 함수 정의는 다음과 같다.

int dbminit(name); int store(key, content); datum fetch(key); int delete(key); datum firstkey(); datum nextkey(key); int dbmclose(); 

Standard UNIX dbm and GNU dbm do not have the same data format in the file. You cannot access a standard UNIX dbm file with GNU dbm! If you want to use an old database with GNU dbm, you must use the conv2gdbm program.

Also, GNU dbm has compatibility functions for ndbm. For ndbm compatibility functions, you need the include file ndbm.h.

표준 유닉스 dbm과 GNU dbm은 같은 형식으로 파일에 자료를 저장하지 않는다. GNU dbm으로 표준 유닉스 dbm 파일을 접근할 수 없다! GNU dbm으로 기존의 데이터베이스를 사용하려면 conv2gdbm 프로그램을 사용하여 변환해야 한다.

GNU dbmndbm과 호환을 위한 함수도 제공한다. ndbm 호환 함수는 헤더파일 ndbm.h에 선언되있다.

Again, just like ndbm, any returned datum can be assumed to be static storage. You do not have to free that memory, the ndbm compatibility functions will do it for you.

The functions are:

DBM *dbm_open(name, flags, mode); void dbm_close(file); datum dbm_fetch(file, key); int dbm_store(file, key, content, flags); int dbm_delete(file, key); datum dbm_firstkey(file); datum dbm_nextkey(file); int dbm_error(file); int dbm_clearerr(file); int dbm_dirfno(file); int dbm_pagfno(file); int dbm_rdonly(file); 

ndbm과 같이 반환된 datum은 정적 메모리에 있다고 가정한다. 그 메모리를 반환하면 안된다. ndbm 호환 함수가 대신 반환한다.

함수는 다음과 같다.

DBM *dbm_open(name, flags, mode); void dbm_close(file); datum dbm_fetch(file, key); int dbm_store(file, key, content, flags); int dbm_delete(file, key); datum dbm_firstkey(file); datum dbm_nextkey(file); int dbm_error(file); int dbm_clearerr(file); int dbm_dirfno(file); int dbm_pagfno(file); int dbm_rdonly(file); 

If you want to compile an old C program that used UNIX dbm or ndbm and want to use gdbm files, execute the following cc command:

cc ... -L /usr/local/lib -lgdbm 

유닉스 dbm이나 ndbm을 사용하는 오래된 C 프로그램을 컴파일 할 때, 다음 cc 명령어를 실행하여 gdbm을 이용한다.

cc ... -L /usr/local/lib -lgdbm 

dbm 파일을 gdbm 형식으로 변환하기

The program conv2gdbm has been provided to help you convert from dbm databases to gdbm. The usage is:

conv2gdbm [-q] [-b block_size] dbm_file [gdbm_file] 

프로그램 conv2gdbmdbm 데이터베이스를 gdbm 형식으로 변환하기 위해서 제공된다. 사용법은 다음과 같다.
conv2gdbm [-q] [-b block_size] dbm_file [gdbm_file] 

The options are:
옵션은 다음과 같다.

-q
Causes conv2gdbm to work quietly.
conv2gdbm이 진행과정을 화면에 출력을 하지않는다.
block_size
Is the same as in gdbm_open.
gdbm_open에서와 같다.
dbm_file
Is the name of the dbm file without the .pag or .dir extensions.
.pag.dir 확장자를 제외한 dbm 파일명.
gdbm_file
Is the complete file name. If not included, the gdbm file name is the same as the dbm file name without any extensions. That is conv2gdbm dbmfile converts the files dbmfile.pag and dbmfile.dir into a gdbm file called dbmfile.
완전한 파일명. 사용하지 않으면 gdbm 파일명은 dbm 파일명에서 확장자를 뺀 것과 같다. 즉, conv2gdbm dbmfile은 파일 dbmfile.pagdbmfile.dirdbmfile라는 gdbm 파일로 변환한다.

문제점과 버그

If you have problems with GNU dbm or think you've found a bug, please report it. Before reporting a bug, make sure you've actually found a real bug. Carefully reread the documentation and see if it really says you can do what you're trying to do. If it's not clear whether you should be able to do something or not, report that too; it's a bug in the documentation!

Before reporting a bug or trying to fix it yourself, try to isolate it to the smallest possible input file that reproduces the problem. Then send us the input file and the exact results gdbm gave you. Also say what you expected to occur; this will help us decide whether the problem was really in the documentation.

GNU dbm에 문제가 있거나 버그를 발견했다고 생각되면 알려줘라. 버그를 알리기 전에 실제로 버그를 발견했는지 확인하라. 문서를 주의있게 다시읽고 의도한 일을 실제로 할 수 있는지 알아봐라. 할 수 있는지 명확하지 않다면 그것도 알려라. 이는 문서의 버그이다!

버그를 알리거나 직접 고치려하기 전에 문제를 만들 수 있는 가능한 최소의 입력 파일을 만들어봐라. 그후 입력파일과 gdbm의 결과를 그대로 우리에게 보내라. 또한 무슨 일이 일어나기를 바랬는지도 알려줘라. 그러면 우리가 문서에 문제가 있는지를 아는데 도움이 된다.

Once you've got a precise problem, send e-mail to:

Internet: `bug-gnu-utils@prep.ai.mit.edu'. UUCP: `mit-eddie!prep.ai.mit.edu!bug-gnu-utils'. 

문제를 발견하면 아래로 메일을 보내라.

인터넷: `bug-gnu-utils@prep.ai.mit.edu'. UUCP: `mit-eddie!prep.ai.mit.edu!bug-gnu-utils'. 

Please include the version number of GNU dbm you are using. You can get this information by printing the variable gdbm_version (see Variables).

Non-bug suggestions are always welcome as well. If you have questions about things that are unclear in the documentation or are just obscure features, please report them too.

사용하는 GNU dbm 버전도 같이 알려줘라. 버전은 변수 gdbm_version을 출력하면 알 수 있다. ("두 유용한 변수" 참고)

버그 외에 제안도 환영한다. 문서에 불분명한 내용이나 애매한 기능이 있다면 이것도 우리에게 알려주길 바란다.

You may contact the author by:

 e-mail: phil@cs.wwu.edu us-mail: Philip A. Nelson Computer Science Department Western Washington University Bellingham, WA 98226 

아래 주소로 저자와 연락할 수 있다.

 e-mail: phil@cs.wwu.edu us-mail: Philip A. Nelson Computer Science Department Western Washington University Bellingham, WA 98226 

You may contact the current maintainer by:

 e-mail: downsj@downsj.com 

아래 주소로 현재 메인테이너와 연락할 수 있다.

 e-mail: downsj@downsj.com 
위로 스크롤