// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x70(%rbp)
callq 0x5cff0
movq -0x70(%rbp), %rax
movq 0x11e9aa(%rip), %rcx    # 0x208ab8
addq $0x10, %rcx
movq %rcx, (%rax)
movl $0xffffffff, 0x38(%rax) # imm = 0xFFFFFFFF
movb $0x0, 0x3c(%rax)
movl $0x80000, -0x18(%rbp)   # imm = 0x80000
movq -0x10(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0x5b6d0
jmp 0xea136
leaq 0xbbaa9(%rip), %rsi     # 0x1a5be6
leaq -0x58(%rbp), %rdi
callq 0x5a1b0
jmp 0xea148
movl -0x14(%rbp), %eax
movq %rax, -0x78(%rbp)
subq $0x6, %rax
ja 0xea18b
movq -0x78(%rbp), %rax
leaq 0xbb760(%rip), %rcx     # 0x1a58c0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0xea375
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0xea36c
movq -0x70(%rbp), %rax
movl $0x2, 0x18(%rax)
movl $0x1, -0x5c(%rbp)
jmp 0xea351
leaq -0x30(%rbp), %rdi
callq 0x5d090
movq %rax, -0x80(%rbp)
jmp 0xea1b1
movq -0x80(%rbp), %rdi
movl -0x18(%rbp), %esi
orl $0x42, %esi
xorl %eax, %eax
movl $0x1b6, %edx            # imm = 0x1B6
callq 0x5aa30
movl %eax, -0x84(%rbp)
jmp 0xea1cf
movq -0x70(%rbp), %rax
movl -0x84(%rbp), %ecx
movl %ecx, 0x38(%rax)
cmpl $-0x1, 0x38(%rax)
je 0xea23b
movq -0x70(%rbp), %rdi
movq (%rdi), %rax
movq 0x40(%rax), %rax
callq *%rax
movq %rax, -0x90(%rbp)
jmp 0xea1f8
movq -0x90(%rbp), %rax
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
jl 0xea239
movq -0x70(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq (%rdi), %rax
movq 0x20(%rax), %rax
callq *%rax
jmp 0xea21d
jmp 0xea239
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x5d140
jmp 0xea36c
jmp 0xea23b
jmp 0xea2fa
leaq -0x30(%rbp), %rdi
callq 0x5d090
movq %rax, -0x98(%rbp)
jmp 0xea252
movq -0x98(%rbp), %rdi
movl -0x18(%rbp), %esi
orl $0x242, %esi            # imm = 0x242
xorl %eax, %eax
movl $0x1b6, %edx            # imm = 0x1B6
callq 0x5aa30
movl %eax, -0x9c(%rbp)
jmp 0xea276
movq -0x70(%rbp), %rax
movl -0x9c(%rbp), %ecx
movl %ecx, 0x38(%rax)
jmp 0xea2fa
leaq -0x30(%rbp), %rdi
callq 0x5d090
movq %rax, -0xa8(%rbp)
jmp 0xea297
movq -0xa8(%rbp), %rdi
movl -0x18(%rbp), %esi
orl $0x2, %esi
xorl %eax, %eax
callq 0x5aa30
movl %eax, -0xac(%rbp)
jmp 0xea2b3
movq -0x70(%rbp), %rax
movl -0xac(%rbp), %ecx
movl %ecx, 0x38(%rax)
jmp 0xea2fa
leaq -0x30(%rbp), %rdi
callq 0x5d090
movq %rax, -0xb8(%rbp)
jmp 0xea2d4
movq -0xb8(%rbp), %rdi
movl -0x18(%rbp), %esi
xorl %eax, %eax
callq 0x5aa30
movl %eax, -0xbc(%rbp)
jmp 0xea2ed
movq -0x70(%rbp), %rax
movl -0xbc(%rbp), %ecx
movl %ecx, 0x38(%rax)
movq -0x70(%rbp), %rax
cmpl $-0x1, 0x38(%rax)
jne 0xea32f
callq 0x5cf30
cmpl $0xd, (%rax)
jne 0xea31b
movq -0x70(%rbp), %rax
movl $0x9, 0x18(%rax)
jmp 0xea326
movq -0x70(%rbp), %rax
movl $0x3, 0x18(%rax)
movl $0x1, -0x5c(%rbp)
jmp 0xea351
movq -0x70(%rbp), %rdi
addq $0x20, %rdi
leaq -0x30(%rbp), %rsi
callq 0x59760
jmp 0xea342
movq -0x70(%rbp), %rax
movb $0x1, 0x3c(%rax)
movl $0x0, -0x5c(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x5d140
leaq -0x30(%rbp), %rdi
callq 0x5df00
addq $0xc0, %rsp
popq %rbp
retq
leaq -0x30(%rbp), %rdi
callq 0x5df00
movq -0x70(%rbp), %rdi
callq 0x5b1a0
movq -0x38(%rbp), %rdi
callq 0x5b6b0
nopw (%rax,%rax)