1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include "lseek.h"
16
17 #include "stat_impl.h"
18 #include "macro.h"
19 #include "n_error.h"
20 #include "file_utils.h"
21 #include "rust_file.h"
22
23 namespace OHOS {
24 namespace CJSystemapi {
25 using namespace std;
26 using namespace OHOS::FileManagement::LibN;
27
Lseek(int32_t fd,int64_t offset,int pos)28 RetDataI64 LseekImpl::Lseek(int32_t fd, int64_t offset, int pos)
29 {
30 LOGI("FS_TEST:: LseekImpl::Lseek start");
31 RetDataI64 ret = { .code = EINVAL, .data = 0 };
32 if (fd < 0) {
33 LOGE("Invalid fd");
34 return ret;
35 }
36
37 SeekPos whence = static_cast<SeekPos>(pos);
38
39 int64_t seekRet = ::Lseek(fd, offset, whence);
40 if (seekRet < 0) {
41 LOGE("Failed to lseek, error:%{public}d", errno);
42 ret.code = errno;
43 return ret;
44 }
45 ret.code = SUCCESS_CODE;
46 ret.data = seekRet;
47 return ret;
48 }
49
50 } // CJSystemapi
51 } // OHOS
52