os-70-350

os-70-350 Commit Details


Date:2013-12-15 14:39:17 (11 years 8 months ago)
Author:Natalie Adams
Branch:master
Commit:e9510a82b47cb3727618c23a8533e1f9f4be86fb
Parents: 36d330c4361589264ab1945b48bffc7741df56ee
Message:Removing VS project for cp and adding windows thread example

Changes:

File differences

cp/Debug/test.txt
1
this is a test1234
cp/Debug/test2.txt
1
this is a test1234
cp/buid.sh
1
2
3
4
#!/bin/bash
gcc -o main main.cpp
./main test.txt test2.txt
cp/build.bat
1
2
3
call ../vcppbuild.bat main
move main.exe cp.exe
cp test.txt test2.txt
cp/cp.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", "cp\cp.vcxproj", "{520F9999-A81C-4EA3-8B7D-5074C97F584C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{520F9999-A81C-4EA3-8B7D-5074C97F584C}.Debug|Win32.ActiveCfg = Debug|Win32
{520F9999-A81C-4EA3-8B7D-5074C97F584C}.Debug|Win32.Build.0 = Debug|Win32
{520F9999-A81C-4EA3-8B7D-5074C97F584C}.Release|Win32.ActiveCfg = Release|Win32
{520F9999-A81C-4EA3-8B7D-5074C97F584C}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
cp/cp/cp.vcxproj
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
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{520F9999-A81C-4EA3-8B7D-5074C97F584C}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>cp</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
cp/cp/cp.vcxproj.filters
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
cp/cp/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
56
57
58
59
60
61
62
63
#include <Windows.h>
void WriteStr(const char * str)
{
// A simple wrapper to output text using WriteFile
HANDLE stdout2 = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD byteswritten;
int length = 0;
const char * cpyptr = str;
while(*cpyptr++) // This doesn't work the way you would expect it
length++;
WriteFile(stdout2, str, length, &byteswritten, NULL);
}
class FileWrapper
{
private:
HANDLE _handle;
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); } // http://msdn.microsoft.com/en-us/library/windows/desktop/ms724211(v=vs.85).aspx
HANDLE 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], GENERIC_READ, OPEN_EXISTING);
if (GetLastError() == ERROR_FILE_NOT_FOUND)
{
WriteStr("Could not find file!");
return 0;
}
// Open destination file
FileWrapper dst(args[2], GENERIC_WRITE, CREATE_ALWAYS);
DWORD numberofbytesread;
DWORD numberofbyteswritten;
char buffer[20];
// Stream the file instead of reading it into memory
while(true)
{
// The buffer parameter is a void pointer which means it can take anything - in this case we just use a char array
// 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);
}
return 0;
}
cp/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
56
57
58
59
60
61
62
63
#include <Windows.h>
void WriteStr(const char * str)
{
// A simple wrapper to output text using WriteFile
HANDLE stdout2 = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD byteswritten;
int length = 0;
const char * cpyptr = str;
while(*cpyptr++) // This doesn't work the way you would expect it
length++;
WriteFile(stdout2, str, length, &byteswritten, NULL);
}
class FileWrapper
{
private:
HANDLE _handle;
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); } // http://msdn.microsoft.com/en-us/library/windows/desktop/ms724211(v=vs.85).aspx
HANDLE 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], GENERIC_READ, OPEN_EXISTING);
if (GetLastError() == ERROR_FILE_NOT_FOUND)
{
WriteStr("Could not find file!");
return 0;
}
// Open destination file
FileWrapper dst(args[2], GENERIC_WRITE, CREATE_ALWAYS);
DWORD numberofbytesread;
DWORD numberofbyteswritten;
char buffer[20];
// Stream the file instead of reading it into memory
while(true)
{
// The buffer parameter is a void pointer which means it can take anything - in this case we just use a char array
// 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);
}
return 0;
}
cp/test.txt
1
THIS IS ONLY A TEST
thread-windows/build.bat
1
../vcbuild.bat main
thread-windows/main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <stdio.h>
#include <windows.h>
DWORD WINAPI ThreadFunc(void* data) {
int i;
for(i = 0; i < 10; i++)
printf("%i\n", i);
return 0;
}
int main() {
HANDLE thread1, thread2;
thread1 = CreateThread(NULL, 0, ThreadFunc, NULL, 0, NULL);
thread2 = CreateThread(NULL, 0, ThreadFunc, NULL, 0, NULL);
WaitForSingleObject(thread1, INFINITE);
WaitForSingleObject(thread2, INFINITE);
}

Archive Download the corresponding diff file

Branches

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