// File: /workspace/github_c_makefile_star2_O1/enzo1982[P]smooth/classes/io/drivers/driver_posix.cpp
// Function: smooth::IO::DriverPOSIX::DriverPOSIX(smooth::String const&, int)
S::IO::DriverPOSIX::DriverPOSIX(const String &file, Int mode) : Driver()
{
	stream	    = -1;
	closeStream = False;

#if defined __WIN32__
	/* Add O_NOINHERIT and O_BINARY options and Unicode prefix on Windows.
	 */
	Int	 options  = O_NOINHERIT | O_BINARY;
	String	 fileName = Directory::MakeExtendedPath(file);
#else
	/* Use O_CLOEXEC option on other systems.
	 */
	Int	 options  = O_CLOEXEC;
	String	 fileName = file;

	/* Set output format to UTF-8 on non-Windows systems.
	 */
	String::OutputFormat	 outputFormat("UTF-8");
#endif

	switch (mode)
	{
		default:
			lastError = IO_ERROR_BADPARAM;

			return;
		case OS_APPEND:		   // open a file for appending data
			stream = open(fileName, options | O_RDWR | O_CREAT, 0666);

			if (stream != -1)
			{
				Int64	 size = GetSize();

				if (size >= 0) Seek(size);
			}

			break;
		case OS_REPLACE:	   // create or overwrite a file
			stream = open(fileName, options | O_RDWR | O_CREAT | O_TRUNC, 0666);

			break;
		case IS_READ | IS_WRITE:   // open a file for reading data
			stream = open(fileName, options | O_RDWR);

			break;
		case IS_READ:		   // open a file in read only mode
			stream = open(fileName, options | O_RDONLY);

			break;
	}

	/* Check if stream was opened successfully.
	 */
	if (stream == -1)
	{
		if (errno == EACCES) lastError = IO_ERROR_NOACCESS;
		else		     lastError = IO_ERROR_UNEXPECTED;

		return;
	}

	streamID = fileName;

	closeStream = True;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x30, %rsp
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
callq 0x58560
movq 0xcb10c(%rip), %rax     # 0x16cad0
addq $0x10, %rax
movq %rax, (%rbx)
movl $0xffffffff, 0x38(%rbx) # imm = 0xFFFFFFFF
movb $0x0, 0x3c(%rbx)
movq %rsp, %rdi
movq %r14, %rsi
callq 0x570b0
leaq 0x7173e(%rip), %rsi     # 0x113126
leaq 0x18(%rsp), %rdi
callq 0x55ed0
cmpl $0x6, %ebp
ja 0xa1abf
movl %ebp, %eax
leaq 0x70ebc(%rip), %rcx     # 0x1128c0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rsp, %rdi
callq 0x585e0
movq %rax, %rdi
movl $0x80042, %esi          # imm = 0x80042
movl $0x1b6, %edx            # imm = 0x1B6
xorl %eax, %eax
callq 0x565c0
movl %eax, 0x38(%rbx)
cmpl $-0x1, %eax
je 0xa1a94
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x40(%rax)
testq %rax, %rax
js 0xa1a94
movq (%rbx), %rcx
movq %rbx, %rdi
movq %rax, %rsi
callq *0x20(%rcx)
jmp 0xa1a94
movq %rsp, %rdi
callq 0x585e0
movl $0x80000, %esi          # imm = 0x80000
jmp 0xa1a87
movq %rsp, %rdi
callq 0x585e0
movq %rax, %rdi
movl $0x80242, %esi          # imm = 0x80242
movl $0x1b6, %edx            # imm = 0x1B6
xorl %eax, %eax
callq 0x565c0
jmp 0xa1a91
movq %rsp, %rdi
callq 0x585e0
movl $0x80002, %esi          # imm = 0x80002
movq %rax, %rdi
xorl %eax, %eax
callq 0x565c0
movl %eax, 0x38(%rbx)
cmpl $-0x1, 0x38(%rbx)
je 0xa1aac
leaq 0x20(%rbx), %rdi
movq %rsp, %rsi
callq 0x555f0
movb $0x1, 0x3c(%rbx)
jmp 0xa1acf
callq 0x58490
cmpl $0xd, (%rax)
jne 0xa1ac8
movl $0x9, 0x18(%rbx)
jmp 0xa1acf
movl $0x2, 0x18(%rbx)
jmp 0xa1acf
movl $0x3, 0x18(%rbx)
leaq 0x18(%rsp), %rdi
callq 0x58680
movq %rsp, %rdi
callq 0x59200
addq $0x30, %rsp
popq %rbx
popq %r14
popq %rbp
retq
jmp 0xa1af6
movq %rax, %r14
jmp 0xa1b03
movq %rax, %r14
jmp 0xa1b0b
movq %rax, %r14
leaq 0x18(%rsp), %rdi
callq 0x58680
movq %rsp, %rdi
callq 0x59200
movq %rbx, %rdi
callq 0x56c30
movq %r14, %rdi
callq 0x57090
nop