os-70-350

os-70-350 Commit Details


Date:2013-11-24 22:09:11 (11 years 9 months ago)
Author:Natalie Adams
Branch:master
Commit:f6324e22160ae2c2d4b3960970a6c5157edfbcbb
Parents: 8ad0be73a293df1811e33513c5c8b9113092ccec
Message:Adding code for Linux and makefile

Changes:

File differences

cp-Linux/Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#------------------------------------------------------------------------------#
# This makefile was generated by 'cbp2make' tool rev.147 #
#------------------------------------------------------------------------------#
WORKDIR = `pwd`
CC = gcc
CXX = g++
AR = ar
LD = g++
WINDRES = windres
INC =
CFLAGS = -Wall -fexceptions
RESINC =
LIBDIR =
LIB =
LDFLAGS =
INC_DEBUG = $(INC)
CFLAGS_DEBUG = $(CFLAGS) -g
RESINC_DEBUG = $(RESINC)
RCFLAGS_DEBUG = $(RCFLAGS)
LIBDIR_DEBUG = $(LIBDIR)
LIB_DEBUG = $(LIB)
LDFLAGS_DEBUG = $(LDFLAGS)
OBJDIR_DEBUG = obj/Debug
DEP_DEBUG =
OUT_DEBUG = bin/Debug/cp-Linux
INC_RELEASE = $(INC)
CFLAGS_RELEASE = $(CFLAGS) -O2
RESINC_RELEASE = $(RESINC)
RCFLAGS_RELEASE = $(RCFLAGS)
LIBDIR_RELEASE = $(LIBDIR)
LIB_RELEASE = $(LIB)
LDFLAGS_RELEASE = $(LDFLAGS) -s
OBJDIR_RELEASE = obj/Release
DEP_RELEASE =
OUT_RELEASE = bin/Release/cp-Linux
OBJ_DEBUG = $(OBJDIR_DEBUG)/main.o
OBJ_RELEASE = $(OBJDIR_RELEASE)/main.o
all: debug release
clean: clean_debug clean_release
before_debug:
test -d bin/Debug || mkdir -p bin/Debug
test -d $(OBJDIR_DEBUG) || mkdir -p $(OBJDIR_DEBUG)
after_debug:
debug: before_debug out_debug after_debug
out_debug: before_debug $(OBJ_DEBUG) $(DEP_DEBUG)
$(LD) $(LIBDIR_DEBUG) -o $(OUT_DEBUG) $(OBJ_DEBUG) $(LDFLAGS_DEBUG) $(LIB_DEBUG)
$(OBJDIR_DEBUG)/main.o: main.cpp
$(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c main.cpp -o $(OBJDIR_DEBUG)/main.o
clean_debug:
rm -f $(OBJ_DEBUG) $(OUT_DEBUG)
rm -rf bin/Debug
rm -rf $(OBJDIR_DEBUG)
before_release:
test -d bin/Release || mkdir -p bin/Release
test -d $(OBJDIR_RELEASE) || mkdir -p $(OBJDIR_RELEASE)
after_release:
release: before_release out_release after_release
out_release: before_release $(OBJ_RELEASE) $(DEP_RELEASE)
$(LD) $(LIBDIR_RELEASE) -o $(OUT_RELEASE) $(OBJ_RELEASE) $(LDFLAGS_RELEASE) $(LIB_RELEASE)
$(OBJDIR_RELEASE)/main.o: main.cpp
$(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c main.cpp -o $(OBJDIR_RELEASE)/main.o
clean_release:
rm -f $(OBJ_RELEASE) $(OUT_RELEASE)
rm -rf bin/Release
rm -rf $(OBJDIR_RELEASE)
.PHONY: before_debug after_debug clean_debug before_release after_release clean_release
cp-Linux/bin/Debug/test.txt
1
abv34asdfasdfasdfdsf123456
cp-Linux/bin/Debug/test2.txt
1
abv34asdfasdfasdfdsf123456
cp-Linux/cp-Linux.cbp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="cp-Linux" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/cp-Linux" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/cp-Linux" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
<Add option="-fexceptions" />
</Compiler>
<Unit filename="main.cpp" />
<Extensions>
<code_completion />
<envvars />
<debugger />
<lib_finder disable_auto="1" />
</Extensions>
</Project>
</CodeBlocks_project_file>
cp-Linux/main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <unistd.h> // read, write
#include <errno.h> // ENOENT
#include <fcntl.h> // O_RDONLY and O_WRONLY
void WriteStr(const char * str)
{
// A simple wrapper to output text using Write
int length = 0;
const char * cpyptr = str;
while(*cpyptr++) // This doesn't work the way you would expect it
length++;
write(1, str, length);
}
class FileWrapper
{
private:
int _handle;
public:
FileWrapper(const char * file, int flags) { this->_handle = open(file, flags); }
~FileWrapper() { close(this->_handle); }
int getHandle() { return this->_handle; }
};
int main(int argc, char * args[])
{
// Parameter checking
if (argc != 3)
{
WriteStr("Please enter two parameters - cp src dst");
return 0;
}
// Open the source
// A little RAII
FileWrapper src(args[1], O_RDONLY);
if (src.getHandle() == ENOENT)
{
WriteStr("Could not find file!");
return 0;
}
FileWrapper dst(args[2], O_WRONLY | O_CREAT);
int numofbytesread;
char buffer[20];
// Stream the file instead of reading it into memory
// The buffer parameter is a void pointer which means it can take anything - in this case we just use a char array
while ((numofbytesread = read(src.getHandle(), buffer, 20)))
write(dst.getHandle(), buffer, numofbytesread);
return 0;
}
cp-test/Debug/test.txt
1
test
cp-test/cp-test.sln
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cp-test", "cp-test\cp-test.vcxproj", "{95FF3465-32A5-4FF2-941C-4D7A163019A1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{95FF3465-32A5-4FF2-941C-4D7A163019A1}.Debug|Win32.ActiveCfg = Debug|Win32
{95FF3465-32A5-4FF2-941C-4D7A163019A1}.Debug|Win32.Build.0 = Debug|Win32
{95FF3465-32A5-4FF2-941C-4D7A163019A1}.Release|Win32.ActiveCfg = Release|Win32
{95FF3465-32A5-4FF2-941C-4D7A163019A1}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
cp/cp/main.cpp
77
88
99
10
10
1111
1212
1313
......
1919
2020
2121
22
22
2323
2424
2525
......
5252
5353
5454
55
55
56
5657
5758
5859
DWORD byteswritten;
int length = 0;
const char * cpyptr = str;
while(*cpyptr++)
while(*cpyptr++) // This doesn't work the way you would expect it
length++;
WriteFile(stdout2, str, length, &byteswritten, NULL);
}
public:
FileWrapper(const char * file, DWORD access, DWORD creation) { this->_handle = CreateFileA(file, access, 0, NULL, creation, FILE_ATTRIBUTE_NORMAL, NULL); }
~FileWrapper() { CloseHandle(this->_handle); }
~FileWrapper() { CloseHandle(this->_handle); } // http://msdn.microsoft.com/en-us/library/windows/desktop/ms724211(v=vs.85).aspx
HANDLE getHandle() { return this->_handle; }
};
while(true)
{
// The buffer parameter is a void pointer which means it can take anything - in this case we just use a char array
ReadFile(src.getHandle(), buffer, 20, &numberofbytesread, NULL);
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa365467(v=vs.85).aspx
ReadFile(src.getHandle(), buffer, 20, &numberofbytesread, NULL); // http://stackoverflow.com/questions/12655120/readfile-function-from-win32-api
if (numberofbytesread == 0)
break;
WriteFile(dst.getHandle(), buffer, numberofbytesread, &numberofbyteswritten, NULL);

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.19461s using 14 queries.