1 /* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
2 
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 
16 #include "tensorflow/c/tf_status.h"
17 
18 #include "tensorflow/c/tf_status_internal.h"
19 #include "tensorflow/core/platform/error.h"
20 #include "tensorflow/core/platform/status.h"
21 
22 using ::tensorflow::IOError;
23 using ::tensorflow::Status;
24 using ::tensorflow::error::Code;
25 
TF_NewStatus()26 TF_Status* TF_NewStatus() { return new TF_Status; }
27 
TF_DeleteStatus(TF_Status * s)28 void TF_DeleteStatus(TF_Status* s) { delete s; }
29 
TF_SetStatus(TF_Status * s,TF_Code code,const char * msg)30 void TF_SetStatus(TF_Status* s, TF_Code code, const char* msg) {
31   if (code == TF_OK) {
32     s->status = Status::OK();
33     return;
34   }
35   s->status = Status(static_cast<Code>(code), tensorflow::StringPiece(msg));
36 }
37 
TF_SetStatusFromIOError(TF_Status * s,int error_code,const char * context)38 void TF_SetStatusFromIOError(TF_Status* s, int error_code,
39                              const char* context) {
40   // TODO(mihaimaruseac): Handle windows when changing its filesystem
41   s->status = IOError(context, error_code);
42 }
43 
TF_GetCode(const TF_Status * s)44 TF_Code TF_GetCode(const TF_Status* s) {
45   return static_cast<TF_Code>(s->status.code());
46 }
47 
TF_Message(const TF_Status * s)48 const char* TF_Message(const TF_Status* s) {
49   return s->status.error_message().c_str();
50 }
51