3 Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials are licensed and made available
5 under the terms and conditions of the BSD License which accompanies this
6 distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <Common/UefiBaseTypes.h>
19 SaveFileToDisk(FilePath, Content)
34 PyObject
*ReturnValue
= Py_False
;
36 Status
= PyArg_ParseTuple(
47 FileHandle
= CreateFile(
50 FILE_SHARE_WRITE
|FILE_SHARE_READ
|FILE_SHARE_DELETE
,
53 FILE_ATTRIBUTE_NORMAL
,
56 if (FileHandle
== INVALID_HANDLE_VALUE
) {
57 PyErr_SetString(PyExc_Exception
, "File creation failure");
61 while (WriteFile(FileHandle
, Data
, DataLength
, &WriteBytes
, NULL
)) {
62 if (DataLength
<= WriteBytes
) {
68 DataLength
-= WriteBytes
;
71 if (DataLength
!= 0) {
72 // file saved unsuccessfully
73 PyErr_SetString(PyExc_Exception
, "File write failure");
78 // Flush buffer may slow down the whole build performance (average 10s slower)
80 //if (!FlushFileBuffers(FileHandle)) {
81 // PyErr_SetString(PyExc_Exception, "File flush failure");
86 ReturnValue
= Py_True
;
89 CloseHandle(FileHandle
);
93 STATIC INT8 SaveFileToDiskDocs
[] = "SaveFileToDisk(): Make sure the file is saved to disk\n";
95 STATIC PyMethodDef PyUtility_Funcs
[] = {
96 {"SaveFileToDisk", (PyCFunction
)SaveFileToDisk
, METH_VARARGS
, SaveFileToDiskDocs
},
101 initPyUtility(VOID
) {
102 Py_InitModule3("PyUtility", PyUtility_Funcs
, "Utilties Module Implemented C Language");