DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Last post Author Topic: Tiny 'Touch' 32 bits program in C (3 kb)  (Read 28,311 times)

Gerome

  • Charter Honorary Member
  • Joined in 2006
  • ***
  • Posts: 154
Re: Tiny 'Touch' 32 bits program in C (3 kb)
« Reply #25 on: October 01, 2006, 07:23 PM »
Just for fun, here's a 1kb C (well, C++) version, that has proper system return code :)

Nice!
Here's a good link btw : http://smallcode.weblogs.us/category/optimization-tricks/
Yours,
(¯`·._.·[Gerome GUILLEMIN]·._.·´¯)
http://www.fbsl.net [FBSL Author]
http://gedd123.free.fr/FBSLv3.zip [FBSL Help file]
(¯`·._.·[If you need help... just ask]·._.·´¯)

Gerome

  • Charter Honorary Member
  • Joined in 2006
  • ***
  • Posts: 154
Re: Tiny 'Touch' 32 bits program in C (3 kb)
« Reply #26 on: October 01, 2006, 08:17 PM »
Hello,

Here is the ported version to FBSL v3 :
One cas easily compare the C version vs the FBSL one and have a look at slight difference of both languages :)
Compiled as 'tiny' Fbsl executable, it's final weight is around 8Kb.
Code: (fbsl)
// ********************************
// Author : Gerome GUILLEMIN
// Coded in FBSL v3
// Date : 01st of October 2006
// ********************************
#DllDeclare Kernel32( "CreateFile", "CloseHandle", "GetSystemTime", "SystemTimeToFileTime", "SetFileTime" )

Function Main()
    Dim %lngHandle = NULL
    Dim $szFileName * MAX_PATH+1
    If CommandCount() = 2 Then
        StrCpy( szFileName, Command(1) )
        lngHandle = CreateFile(szFileName, GENERIC_WRITE, _
                    FILE_SHARE_READ + FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0)
        If lngHandle AndAlso lngHandle <> INVALID_HANDLE_VALUE Then
            SetFileToCurrentTime( lngHandle )
            CloseHandle( lngHandle )
            Return 1 // => 1 will be the OK return
        End If
    End If
Return 0 // => 0 will be the KO return
End Function

Function SetFileToCurrentTime(Byval %hFile)
  Dim $ft * 16 'FILETIME
  Dim $st * 16 'SYSTEMTIME

  GetSystemTime(@st)                 // gets current time
  SystemTimeToFileTime(@st, @ft)     // converts to file time format
  Return SetFileTime(hFile, 0, 0, @ft) // sets last-write time for file
End Function

See the attached Zip file to get the whole thing.
Enjoy FBSL !
Yours,
(¯`·._.·[Gerome GUILLEMIN]·._.·´¯)
http://www.fbsl.net [FBSL Author]
http://gedd123.free.fr/FBSLv3.zip [FBSL Help file]
(¯`·._.·[If you need help... just ask]·._.·´¯)
« Last Edit: October 01, 2006, 08:35 PM by Gerome »

Original address: https://www.donationcoder.com/forum/index.php?topic=5537.0