Module: FFI::LastError

Defined in:
ext/ffi_c/LastError.c,
ext/ffi_c/LastError.c

Overview

This module defines a couple of method to set and get errno for current thread.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.errorNumeric

Get errno value.

Returns:

  • (Numeric)

128
129
130
131
132
# File 'ext/ffi_c/LastError.c', line 128

static VALUE
get_last_error(VALUE self)
{
    return INT2NUM(thread_data_get()->td_errno);
}

.error(error) ⇒ nil

Set errno value.

Parameters:

  • error (Numeric)

Returns:

  • (nil)

154
155
156
157
158
159
160
161
162
163
164
165
# File 'ext/ffi_c/LastError.c', line 154

static VALUE
set_last_error(VALUE self, VALUE error)
{

#ifdef _WIN32
    SetLastError(NUM2INT(error));
#else
    errno = NUM2INT(error);
#endif

    return Qnil;
}

.winapi_errorNumeric

Get GetLastError() value. Only Windows or Cygwin.

Returns:

  • (Numeric)

140
141
142
143
144
# File 'ext/ffi_c/LastError.c', line 140

static VALUE
get_last_winapi_error(VALUE self)
{
    return INT2NUM(thread_data_get()->td_winapi_errno);
}

.error(error) ⇒ nil

Set GetLastError() value. Only on Windows and Cygwin.

Parameters:

  • error (Numeric)

Returns:

  • (nil)

174
175
176
177
178
179
# File 'ext/ffi_c/LastError.c', line 174

static VALUE
set_last_winapi_error(VALUE self, VALUE error)
{
    SetLastError(NUM2INT(error));
    return Qnil;
}

Instance Method Details

#errorNumeric (private)

Get errno value.

Returns:

  • (Numeric)

128
129
130
131
132
# File 'ext/ffi_c/LastError.c', line 128

static VALUE
get_last_error(VALUE self)
{
    return INT2NUM(thread_data_get()->td_errno);
}

#error(error) ⇒ nil (private)

Set errno value.

Parameters:

  • error (Numeric)

Returns:

  • (nil)

154
155
156
157
158
159
160
161
162
163
164
165
# File 'ext/ffi_c/LastError.c', line 154

static VALUE
set_last_error(VALUE self, VALUE error)
{

#ifdef _WIN32
    SetLastError(NUM2INT(error));
#else
    errno = NUM2INT(error);
#endif

    return Qnil;
}

#winapi_errorNumeric (private)

Get GetLastError() value. Only Windows or Cygwin.

Returns:

  • (Numeric)

140
141
142
143
144
# File 'ext/ffi_c/LastError.c', line 140

static VALUE
get_last_winapi_error(VALUE self)
{
    return INT2NUM(thread_data_get()->td_winapi_errno);
}

#error(error) ⇒ nil (private)

Set GetLastError() value. Only on Windows and Cygwin.

Parameters:

  • error (Numeric)

Returns:

  • (nil)

174
175
176
177
178
179
# File 'ext/ffi_c/LastError.c', line 174

static VALUE
set_last_winapi_error(VALUE self, VALUE error)
{
    SetLastError(NUM2INT(error));
    return Qnil;
}