4141#include "tail_multiline.h"
4242#include "tail_scan.h"
4343
44- #ifdef _MSC_VER
45- static int get_inode (int fd , uint64_t * inode , struct flb_tail_config * ctx )
46- {
47- HANDLE h ;
48- BY_HANDLE_FILE_INFORMATION info ;
49-
50- h = _get_osfhandle (fd );
51- if (h == INVALID_HANDLE_VALUE ) {
52- flb_plg_error (ctx -> ins , "cannot convert fd:%i into HANDLE" , fd );
53- return -1 ;
54- }
55-
56- if (GetFileInformationByHandle (h , & info ) == 0 ) {
57- flb_plg_error (ctx -> ins , "cannot get file info for fd:%i" , fd );
58- return -1 ;
59- }
60- * inode = (uint64_t ) info .nFileIndexHigh ;
61- * inode = * inode << 32 | info .nFileIndexLow ;
62- return 0 ;
63- }
44+ #ifdef FLB_SYSTEM_WINDOWS
45+ #include "win32.h"
6446#endif
6547
6648static inline void consume_bytes (char * buf , int bytes , int length )
6749{
6850 memmove (buf , buf + bytes , length - bytes );
6951}
7052
71- #ifdef _MSC_VER
72- /*
73- * Open a file for reading. We need to use CreateFileA() instead of
74- * open(2) to avoid automatic file locking.
75- */
76- static int open_file (const char * path )
77- {
78- HANDLE h ;
79- h = CreateFileA (path ,
80- GENERIC_READ ,
81- FILE_SHARE_READ |FILE_SHARE_WRITE |FILE_SHARE_DELETE ,
82- NULL , /* lpSecurityAttributes */
83- OPEN_EXISTING , /* dwCreationDisposition */
84- 0 , /* dwFlagsAndAttributes */
85- NULL ); /* hTemplateFile */
86- if (h == INVALID_HANDLE_VALUE ) {
87- return -1 ;
88- }
89- return _open_osfhandle ((intptr_t ) h , _O_RDONLY );
90- }
91- #endif
92-
9353static int unpack_and_pack (msgpack_packer * pck , msgpack_object * root ,
9454 const char * key , size_t key_len ,
9555 const char * val , size_t val_len )
@@ -599,11 +559,7 @@ int flb_tail_file_append(char *path, struct stat *st, int mode,
599559 return -1 ;
600560 }
601561
602- #ifdef _MSC_VER
603- fd = open_file (path );
604- #else
605562 fd = open (path , O_RDONLY );
606- #endif
607563 if (fd == -1 ) {
608564 flb_errno ();
609565 flb_plg_error (ctx -> ins , "cannot open %s" , path );
@@ -621,7 +577,6 @@ int flb_tail_file_append(char *path, struct stat *st, int mode,
621577 file -> fd = fd ;
622578
623579 /* On non-windows environments check if the original path is a link */
624- #ifndef _MSC_VER
625580 struct stat lst ;
626581 ret = lstat (path , & lst );
627582 if (ret == 0 ) {
@@ -630,7 +585,6 @@ int flb_tail_file_append(char *path, struct stat *st, int mode,
630585 file -> link_inode = lst .st_ino ;
631586 }
632587 }
633- #endif
634588
635589 /*
636590 * Duplicate string into 'file' structure, the called function
@@ -649,13 +603,7 @@ int flb_tail_file_append(char *path, struct stat *st, int mode,
649603 goto error ;
650604 }
651605
652- #ifdef _MSC_VER
653- if (get_inode (fd , & file -> inode , ctx )) {
654- goto error ;
655- }
656- #else
657606 file -> inode = st -> st_ino ;
658- #endif
659607 file -> offset = 0 ;
660608 file -> size = st -> st_size ;
661609 file -> buf_len = 0 ;
0 commit comments