28b43144e5
when interacting with the system. What we get from and need to hand to the VM is utf8. What we get from and need to hand to the system is in the current code page. R=sgjesse@google.com BUG= Review URL: https://codereview.chromium.org//11275281 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@14851 260f80e4-7a28-3924-810f-c04153c831b5
68 lines
1.8 KiB
C++
68 lines
1.8 KiB
C++
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
#ifndef BIN_UTILS_H_
|
|
#define BIN_UTILS_H_
|
|
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include "include/dart_api.h"
|
|
#include "platform/globals.h"
|
|
|
|
class OSError {
|
|
public:
|
|
enum SubSystem {
|
|
kSystem,
|
|
kGetAddressInfo,
|
|
kUnknown = -1
|
|
};
|
|
|
|
OSError();
|
|
OSError(int code, const char* message, SubSystem sub_system) {
|
|
sub_system_ = sub_system;
|
|
code_ = code;
|
|
message_ = NULL; // SetMessage will free existing message.
|
|
SetMessage(message);
|
|
}
|
|
virtual ~OSError() { free(message_); }
|
|
|
|
SubSystem sub_system() { return sub_system_; }
|
|
int code() { return code_; }
|
|
char* message() { return message_; }
|
|
void SetCodeAndMessage(SubSystem sub_system, int code);
|
|
|
|
private:
|
|
void set_sub_system(SubSystem sub_system) { sub_system_ = sub_system; }
|
|
void set_code(int code) { code_ = code; }
|
|
void SetMessage(const char* message) {
|
|
free(message_);
|
|
if (message == NULL) {
|
|
message_ = NULL;
|
|
} else {
|
|
message_ = strdup(message);
|
|
}
|
|
}
|
|
|
|
SubSystem sub_system_;
|
|
int code_;
|
|
char* message_;
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(OSError);
|
|
};
|
|
|
|
class StringUtils {
|
|
public:
|
|
// The following methods convert the argument if needed. The
|
|
// conversions are only needed on Windows. If the methods returns a
|
|
// pointer that is different from the input pointer the returned
|
|
// pointer is allocated with malloc and should be freed using free.
|
|
static const char* SystemStringToUtf8(const char* str);
|
|
static char* SystemStringToUtf8(char* str);
|
|
static const char* Utf8ToSystemString(const char* utf8);
|
|
static char* Utf8ToSystemString(char* utf8);
|
|
};
|
|
|
|
#endif // BIN_UTILS_H_
|