// File: /workspace/github_c_makefile_star2_O2/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 0x59850
movq 0xc4dd8(%rip), %rax     # 0x161ad0
addq $0x10, %rax
movq %rax, (%rbx)
orl $-0x1, 0x38(%rbx)
movb $0x0, 0x3c(%rbx)
movq %rsp, %rdi
movq %r14, %rsi
callq 0x58280
leaq 0x654ad(%rip), %rsi     # 0x1021c6
leaq 0x18(%rsp), %rdi
callq 0x56fa0
cmpl $0x6, %ebp
ja 0x9ce00
movl %ebp, %eax
leaq 0x64c2f(%rip), %rcx     # 0x101964
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rsp, %rdi
callq 0x598d0
movq %rax, %rdi
movl $0x80042, %esi          # imm = 0x80042
movl $0x1b6, %edx            # imm = 0x1B6
xorl %eax, %eax
callq 0x576d0
movl %eax, 0x38(%rbx)
cmpl $-0x1, %eax
je 0x9cded
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x40(%rax)
testq %rax, %rax
js 0x9cd80
movq (%rbx), %rcx
movq %rbx, %rdi
movq %rax, %rsi
callq *0x20(%rcx)
movl 0x38(%rbx), %eax
jmp 0x9cdd6
movq %rsp, %rdi
callq 0x598d0
movq %rax, %rdi
movl $0x80000, %esi          # imm = 0x80000
xorl %eax, %eax
callq 0x576d0
jmp 0x9cdd3
movq %rsp, %rdi
callq 0x598d0
movq %rax, %rdi
movl $0x80242, %esi          # imm = 0x80242
movl $0x1b6, %edx            # imm = 0x1B6
xorl %eax, %eax
callq 0x576d0
jmp 0x9cdd3
movq %rsp, %rdi
callq 0x598d0
movq %rax, %rdi
movl $0x80002, %esi          # imm = 0x80002
xorl %eax, %eax
callq 0x576d0
movl %eax, 0x38(%rbx)
cmpl $-0x1, %eax
je 0x9cded
leaq 0x20(%rbx), %rdi
movq %rsp, %rsi
callq 0x56630
movb $0x1, 0x3c(%rbx)
jmp 0x9ce10
callq 0x59780
cmpl $0xd, (%rax)
jne 0x9ce09
movl $0x9, 0x18(%rbx)
jmp 0x9ce10
movl $0x2, 0x18(%rbx)
jmp 0x9ce10
movl $0x3, 0x18(%rbx)
leaq 0x18(%rsp), %rdi
callq 0x59970
movq %rsp, %rdi
callq 0x5a588
addq $0x30, %rsp
popq %rbx
popq %r14
popq %rbp
retq
jmp 0x9ce37
movq %rax, %r14
jmp 0x9ce44
movq %rax, %r14
jmp 0x9ce4c
movq %rax, %r14
leaq 0x18(%rsp), %rdi
callq 0x59970
movq %rsp, %rdi
callq 0x5a588
movq %rbx, %rdi
callq 0x57db0
movq %r14, %rdi
callq 0x58260