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)

132
133
134
135
136
# File 'ext/ffi_c/LastError.c', line 132

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)

158
159
160
161
162
163
164
165
166
167
168
169
# File 'ext/ffi_c/LastError.c', line 158

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)

144
145
146
147
148
# File 'ext/ffi_c/LastError.c', line 144

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)

178
179
180
181
182
183
# File 'ext/ffi_c/LastError.c', line 178

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)

132
133
134
135
136
# File 'ext/ffi_c/LastError.c', line 132

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)

158
159
160
161
162
163
164
165
166
167
168
169
# File 'ext/ffi_c/LastError.c', line 158

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)

144
145
146
147
148
# File 'ext/ffi_c/LastError.c', line 144

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)

178
179
180
181
182
183
# File 'ext/ffi_c/LastError.c', line 178

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