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