Method: AIX::Errlog::Errlog#initialize
- Defined in:
- lib/aix/errlog/errlog.rb
#initialize(path = '/var/adm/ras/errlog'.freeze, mode = 'r'.freeze) ⇒ Errlog
path is the string path to the file. mode matches as closely as possible to the semantics of the fopen mode.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/aix/errlog/errlog.rb', line 72 def initialize(path='/var/adm/ras/errlog'.freeze, mode='r'.freeze) mode_r = mode.include? 'r' mode_w = mode.include? 'w' mode_a = mode.include? 'a' mode_x = mode.include? 'x' mode_p = mode.include? '+' mode_flags = if mode_p Constants::O_RDRW elsif mode_r Constants::O_RDONLY else Constants::O_WRONLY end mode_flags |= Constants::O_CREAT unless mode_r mode_flags |= Constants::O_TRUNC if mode_w mode_flags |= Constants::O_APPEND if mode_a mode_flags |= Constants::O_EXCL if mode_x handle_p = FFI::MemoryPointer.new(:pointer) status = Lib.errlog_open( path, mode_flags, Constants::LE_MAGIC, handle_p, ) Errors.throw(status, "path: #{path}, mode: #{mode}") unless status == :ok @enum_active = false # Just hold the handle directly @handle = handle_p.get_pointer end |