]> git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/c_glib/arrow-glib/file.cpp
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / c_glib / arrow-glib / file.cpp
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20 #include <arrow/api.h>
21
22 #include <arrow-glib/error.hpp>
23 #include <arrow-glib/file.hpp>
24 #include <arrow-glib/file-mode.hpp>
25
26 G_BEGIN_DECLS
27
28 /**
29 * SECTION: file
30 * @title: GArrowFile
31 * @short_description: File interface
32 *
33 * #GArrowFile is an interface for file.
34 */
35
36 G_DEFINE_INTERFACE(GArrowFile,
37 garrow_file,
38 G_TYPE_OBJECT)
39
40 static void
41 garrow_file_default_init(GArrowFileInterface *iface)
42 {
43 }
44
45 /**
46 * garrow_file_close:
47 * @file: A #GArrowFile.
48 * @error: (nullable): Return location for a #GError or %NULL.
49 *
50 * Returns: %TRUE on success, %FALSE if there was an error.
51 */
52 gboolean
53 garrow_file_close(GArrowFile *file,
54 GError **error)
55 {
56 auto arrow_file = garrow_file_get_raw(file);
57
58 auto status = arrow_file->Close();
59 return garrow_error_check(error, status, "[io][file][close]");
60 }
61
62 /**
63 * garrow_file_is_closed:
64 * @file: A #GArrowFile.
65 *
66 * Returns: %TRUE if the @file is already closed, %FALSE otherwise.
67 *
68 * Since: 0.13.0
69 */
70 gboolean
71 garrow_file_is_closed(GArrowFile *file)
72 {
73 auto arrow_file = garrow_file_get_raw(file);
74 return arrow_file->closed();
75 }
76
77 /**
78 * garrow_file_tell:
79 * @file: A #GArrowFile.
80 * @error: (nullable): Return location for a #GError or %NULL.
81 *
82 * Returns: The current offset on success, -1 if there was an error.
83 */
84 gint64
85 garrow_file_tell(GArrowFile *file,
86 GError **error)
87 {
88 auto arrow_file = garrow_file_get_raw(file);
89
90 const auto position = arrow_file->Tell();
91 if (garrow::check(error, position, "[io][file][tell]")) {
92 return position.ValueOrDie();
93 } else {
94 return -1;
95 }
96 }
97
98 /**
99 * garrow_file_get_mode:
100 * @file: A #GArrowFile.
101 *
102 * Returns: The mode of the file.
103 */
104 GArrowFileMode
105 garrow_file_get_mode(GArrowFile *file)
106 {
107 auto arrow_file = garrow_file_get_raw(file);
108
109 auto arrow_mode = arrow_file->mode();
110 return garrow_file_mode_from_raw(arrow_mode);
111 }
112
113 G_END_DECLS
114
115 std::shared_ptr<arrow::io::FileInterface>
116 garrow_file_get_raw(GArrowFile *file)
117 {
118 auto *iface = GARROW_FILE_GET_IFACE(file);
119 return iface->get_raw(file);
120 }