1 /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3  *     Copyright 2010 Couchbase, Inc
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 #include "functional_util.h"
19 
_set_random_string(char *str, int len)20 void _set_random_string(char *str, int len)
21 {
22     str[len--] = 0;
23     do {
24         str[len] = '!' + random('~'-'!');
25     } while (len--);
26 }
27 
_set_random_string_smallabt(char *str, int len)28 void _set_random_string_smallabt(char *str, int len)
29 {
30     str[len--] = 0;
31     do {
32         str[len] = 'a' + random('z'-'a');
33     } while (len--);
34 }
35 
_disk_dump(const char *filepath, size_t pos, size_t bytes)36 int _disk_dump(const char *filepath, size_t pos, size_t bytes) {
37     struct filemgr_ops *ops = get_filemgr_ops();
38     int fd = ops->open(filepath, O_CREAT| O_RDWR, 0666);
39     if (fd < 0) {
40         fprintf(stderr, "failure to open %s\n", filepath);
41         return fd;
42     }
43     char *buf = (char *)malloc(bytes);
44     if (!buf) {
45         return -2;
46     }
47     if (ops->pwrite(fd, buf, bytes, pos) != (int) bytes) {
48         return -1;
49     }
50     ops->close(fd);
51     free(buf);
52     return fd;
53 }
54 
logCallbackFunc(int err_code, const char *err_msg, void *pCtxData)55 void logCallbackFunc(int err_code,
56                      const char *err_msg,
57                      void *pCtxData) {
58     fprintf(stderr, "%s - error code: %d, error message: %s\n",
59             (char *) pCtxData, err_code, err_msg);
60 }
61 
62