CUBRID Engine  latest
es_common.c
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 /*
20  * es_common.c - common utilities for external storage API (at client and server)
21  */
22 
23 #include "config.h"
24 
25 #include <string.h>
26 #include <sys/types.h>
27 #include <assert.h>
28 #if !defined (WINDOWS)
29 #include <sys/time.h>
30 #endif
31 
32 #include "porting.h"
33 #include "memory_hash.h"
34 #include "es_common.h"
35 
36 /*
37  * es_get_type -
38  *
39  * return: enum ES_TYPE
40  * uri(in):
41  */
42 ES_TYPE
43 es_get_type (const char *uri)
44 {
45  if (!strncmp (uri, ES_OWFS_PATH_PREFIX, sizeof (ES_OWFS_PATH_PREFIX) - 1))
46  {
47  return ES_OWFS;
48  }
49  else if (!strncmp (uri, ES_POSIX_PATH_PREFIX, sizeof (ES_POSIX_PATH_PREFIX) - 1))
50  {
51  return ES_POSIX;
52  }
53  else if (!strncmp (uri, ES_LOCAL_PATH_PREFIX, sizeof (ES_LOCAL_PATH_PREFIX) - 1))
54  {
55  return ES_LOCAL;
56  }
57  return ES_NONE;
58 }
59 
60 /*
61  * es_get_type_string -
62  *
63  * return: name of ES_TYPE
64  * type(in):
65  */
66 const char *
68 {
69  if (type == ES_OWFS)
70  {
71  return ES_OWFS_PATH_PREFIX;
72  }
73  else if (type == ES_POSIX)
74  {
75  return ES_POSIX_PATH_PREFIX;
76  }
77  else if (type == ES_LOCAL)
78  {
79  return ES_LOCAL_PATH_PREFIX;
80  }
81  return "none";
82 }
83 
84 /*
85  * es_name_hash_func -
86  *
87  * return:
88  * size(in):
89  * name(in):
90  */
91 unsigned int
92 es_name_hash_func (int size, const char *name)
93 {
94  assert (size >= 0);
95  return (int) mht_5strhash (name, (unsigned int) size);
96 }
97 
98 /*
99  * es_get_unique_num -
100  */
101 UINT64
103 {
104  struct timeval tv;
105  gettimeofday (&tv, NULL);
106 
107  return tv.tv_sec * 1000000ULL + tv.tv_usec;
108 }
UINT64 es_get_unique_num(void)
Definition: es_common.c:102
#define ES_LOCAL_PATH_PREFIX
Definition: es_common.h:38
#define assert(x)
const char * es_get_type_string(ES_TYPE type)
Definition: es_common.c:67
#define ES_OWFS_PATH_PREFIX
Definition: es_common.h:36
#define NULL
Definition: freelistheap.h:34
unsigned int mht_5strhash(const void *key, const unsigned int ht_size)
Definition: memory_hash.c:521
ES_TYPE
Definition: es_common.h:28
#define ES_POSIX_PATH_PREFIX
Definition: es_common.h:37
unsigned int es_name_hash_func(int size, const char *name)
Definition: es_common.c:92
ES_TYPE es_get_type(const char *uri)
Definition: es_common.c:43