PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
smgrtype.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * smgrtype.c
4  * storage manager type
5  *
6  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  *
10  * IDENTIFICATION
11  * src/backend/storage/smgr/smgrtype.c
12  *
13  *-------------------------------------------------------------------------
14  */
15 #include "postgres.h"
16 
17 #include "storage/smgr.h"
18 #include "utils/builtins.h"
19 
20 
21 typedef struct smgrid
22 {
23  const char *smgr_name;
24 } smgrid;
25 
26 /*
27  * StorageManager[] -- List of defined storage managers.
28  */
29 static const smgrid StorageManager[] = {
30  {"magnetic disk"}
31 };
32 
33 static const int NStorageManagers = lengthof(StorageManager);
34 
35 
36 Datum
38 {
39  char *s = PG_GETARG_CSTRING(0);
40  int16 i;
41 
42  for (i = 0; i < NStorageManagers; i++)
43  {
44  if (strcmp(s, StorageManager[i].smgr_name) == 0)
45  PG_RETURN_INT16(i);
46  }
47  elog(ERROR, "unrecognized storage manager name \"%s\"", s);
48  PG_RETURN_INT16(0);
49 }
50 
51 Datum
53 {
54  int16 i = PG_GETARG_INT16(0);
55  char *s;
56 
57  if (i >= NStorageManagers || i < 0)
58  elog(ERROR, "invalid storage manager ID: %d", i);
59 
60  s = pstrdup(StorageManager[i].smgr_name);
62 }
63 
64 Datum
66 {
67  int16 a = PG_GETARG_INT16(0);
68  int16 b = PG_GETARG_INT16(1);
69 
70  PG_RETURN_BOOL(a == b);
71 }
72 
73 Datum
75 {
76  int16 a = PG_GETARG_INT16(0);
77  int16 b = PG_GETARG_INT16(1);
78 
79  PG_RETURN_BOOL(a != b);
80 }
signed short int16
Definition: c.h:245
Datum smgrout(PG_FUNCTION_ARGS)
Definition: smgrtype.c:52
char * pstrdup(const char *in)
Definition: mcxt.c:1076
#define PG_RETURN_INT16(x)
Definition: fmgr.h:316
#define lengthof(array)
Definition: c.h:556
Datum smgrne(PG_FUNCTION_ARGS)
Definition: smgrtype.c:74
#define ERROR
Definition: elog.h:43
static const smgrid StorageManager[]
Definition: smgrtype.c:29
const char * smgr_name
Definition: smgrtype.c:23
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
uintptr_t Datum
Definition: postgres.h:372
#define PG_GETARG_INT16(n)
Definition: fmgr.h:236
struct smgrid smgrid
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:322
Datum smgrin(PG_FUNCTION_ARGS)
Definition: smgrtype.c:37
int i
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:242
#define PG_FUNCTION_ARGS
Definition: fmgr.h:158
static const int NStorageManagers
Definition: smgrtype.c:33
#define elog
Definition: elog.h:219
Datum smgreq(PG_FUNCTION_ARGS)
Definition: smgrtype.c:65